[英]how to pass array of object into component, Type x is not assignable to type 'IntrinsicAttributes & x'
array type looks like MyType: {name: string, age: number}[]
, props type in component is the same数组类型看起来像
MyType: {name: string, age: number}[]
,组件中的道具类型相同
<Content data={arrOfObj} /> // warning
const Content: React.FC<MyType> = (data) => {...}
how to pass it into component correctly?如何正确地将其传递给组件? and I also think in the component prop type actually is not equal to MyType.
而且我也认为组件中的道具类型实际上不等于MyType。 To get access to data you need to write the following
data.data
, but because of ts thinks data is an array, you can`t write in this way要访问数据,您需要编写以下
data.data
,但是由于 ts 认为 data 是一个数组,所以不能这样写
This is probably what you wanted这可能是你想要的
<Content data={arrOfObj} /> // warning
const Content: React.FC<{ data: MyType }> = ({ data }) => {...}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.