Can someone please explain why this isn’t working?
I have a simple react component.
interface iRowData{
name: string
}
export default function ResultsSection(data: iRowData[]) {
return <div>Results</div>
}
I get an error when I use this in another component.
export default function NewPage(){
const rowData:iRowData[] = []
return <ResultsSection data={rowData} />
}
The word data is highlighted red, and this is the error I keep getting.
Type '{ data: iRowData[]; }' is not assignable to type 'IntrinsicAttributes & iRowData[]'.
Property 'data' does not exist on type 'IntrinsicAttributes & iRowData[]'.ts(2322)
(property) data: iRowData[]
2
Answers
You need to pass props in as an object:
Notice that ResultsSection now takes an object with property
data: iResults[]
, rather than taking a single parameter of that type.I also notice that you’re using two different types;
iRowData
andiResults
. Is this intentional? Is there any overlap between these two types? If they are completely different, you’ll still get a different error.I think you need to unpack the incoming parameters, e.g.