我刚开始打字,试着用编码来学习。这里我有一个组件,它有isOrange = true。
<InfoBox isOrange />当我试图访问时,它会是这样的:function InfoBox({ isOrange }) { return ( ...)},但是它给了我一个错误:'Type '{ isOrange: true; }' is not assignable to type 'IntrinsicAttributes'. Property 'isOrange' does not exist on type 'IntrinsicAttributes'.ts(2322)',如果我正确地理解了它,我应该有某种接口来使它工作?对不起,英语不是我的母语。
发布于 2021-12-23 09:26:40
正如我所看到的,您试图将数据传递给名为InfoBox的子组件,对吗?如果是这样的话,您必须在InfoBox组件上添加一个接口,以便它知道接下来的数据。
interface Props {
isOrange:boolean;
}然后将道具传递给子组件的功能。
const childComponent:React.FC<Props> = ({isOrange}) => {
//here the code
}https://stackoverflow.com/questions/66422530
复制相似问题