Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Property does not exist on interface in React Typescript

I am pretty new to React but with some Angular attempts before.

I was actually trying to implement a component which accepts a data model or object as parameter

Looks like this

import react from 'react'

interface SmbListItem{
    index:number;
    primary:string;
    secondary:string;
}
   

export default function SmbList({props}:SmbListItem){
    return(
        <>

        </>
    );
}

But its saying props does not exists on SmbListItem

What I did wrong?

Also requesting a suggestion on interface or types are the best option in this situation

like image 734
Sandeep Thomas Avatar asked Sep 16 '26 17:09

Sandeep Thomas


1 Answers

import react from 'react'

interface SmbListItem{
    index:number;
    primary:string;
    secondary:string;
}
   

export default function SmbList({index, primary, secondary}:SmbListItem){
    return(
        <>

        </>
    );
}

There is no such props defined in your Interface Props

Even if you are not using Tsand you are sure about the props you would destructure your props like this

export default function SmbList({index, primary, secondary}){
    return(
        <></>
    );
}

For Your Second Question Have a look into Types vs Interface

like image 52
Azhar Uddin Sheikh Avatar answered Sep 18 '26 21:09

Azhar Uddin Sheikh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!