【发布时间】:2020-04-14 19:04:16
【问题描述】:
场景:
我创建了 Text 组件;另一个 Tag 组件嵌入其中。
问题:
如何输入才能使其正常工作?现在出现一个错误,它不接受所需的样式。
错误是这样的:
Type '{ children: ReactNode; classNames: any; }' is not assignable to type 'IntrinsicAttributes'. Property 'children' does not exist on type 'IntrinsicAttributes'.ts(2322)
这是我的代码:
import React, { ReactNode } from 'react';
import styles from './Text.module.css';
import classNames from 'classnames/bind';
const cx = classNames.bind(styles);
interface ITextProps {
variant: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | 'p1' | 'p2' | 'p3';
bold?: boolean;
}
const tags = {
h1: 'h1',
h2: 'h2',
h3: 'h3',
h4: 'h4',
h5: 'h5',
h6: 'h6',
p1: 'p',
p2: 'p',
p3: 'p',
};
const Text: React.FC<ITextProps> = ({ children, variant, bold }) => {
const Tag = tags[variant];
return <Tag classNames={cx({ title: variant === 'h1' })}>{children}</Tag>;
};
export default Text;
【问题讨论】:
-
有帖子解决了您的问题吗?请提供一些反馈将不胜感激。见What should I do when someone answers my question?
-
现在我正在尝试根据您的帮助更改我的代码。谢谢。
标签: reactjs typescript