如何使用tsx将对象传递给reactjs中的子组件 我尝试这种方式时遇到此错误。在哪里可以声明类型?Property 'value' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes<ShipmentCard>
Cards.tsx
render() {
return (
<div>
{this.state.card.map((card: any) => (
<ShipmentCard key={card.id} value={card}/>
))}
</div>
);
}
完整的错误消息是:
输入'{键:任意;数据:任何;}'不能分配给'IntrinsicAttributes&IntrinsicClassAttributes&Readonly <{}>&Readonly <{children ?: ReactNode; }>'。属性'data'在类型'IntrinsicAttributes&IntrinsicClassAttributes&Readonly <{}>和Readonly <{children ?:上不存在:ReactNode; }>'
如果使用打字稿,则必须在ShipmentCard.tsx中声明所有道具
interface ShipmentCardProps {
key: string;
value: {}
}
interface ShipmentCardState {}
class ShipmentCard extends React.Component<ShipmentCardProps, ShipmentCardState> {
}
export default ShipmentCard
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句