如何使用 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>
);
}
完整的错误信息是:
Type '{ key: any; data: any; }' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes & Readonly<{}> & Readonly<{ children?: ReactNode; }>'. Property 'data' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes & Readonly<{}> & Readonly<{ children?: ReactNode; }>'
最佳答案
如果您使用的是 typescript ,那么您必须在 ShipmentCard.tsx 中声明所有 Prop
interface ShipmentCardProps {
key: string;
value: {}
}
interface ShipmentCardState {}
class ShipmentCard extends React.Component<ShipmentCardProps, ShipmentCardState> {
}
export default ShipmentCard
关于reactjs - 如何使用 typescript 在reactjs中传递数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57348905/