Home > Software design >  how to pass array of object into component, Type x is not assignable to type 'IntrinsicAttribut
how to pass array of object into component, Type x is not assignable to type 'IntrinsicAttribut

Time:08-31

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

CodePudding user response:

This is probably what you wanted

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

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