简体   繁体   中英

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

<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. 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

This is probably what you wanted

<Content data={arrOfObj} /> // warning

const Content: React.FC<{ data: MyType }> = ({ data }) => {...}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM