Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

React Typescript crazy

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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[]

>Solution :

I think you need to unpack the incoming parameters, e.g.

interface iResults {
   name: string;
}

interface ResultSectionProps {
   data: iResults[];
}

export default function ResultsSection({ data }: ResultSectionProps) {
   return <div>Results</div>
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading