How to create type for an object and display the name of that object

Viewed 19

I am using react-data-table-component library to display some data from the backend

The data received is like this:

[
{
  id:1,
  nickname:"nickname"
  Users:[{
    name:"username"
  }]
}
]

The datatable requires 2 parameters as props, columns, and data.

the type for this i have done like this:

type DataRow = {
  id: number;
  nickname:string,
  Users:string
};

and column prop:

const columns: TableColumn<DataRow>[] = [
  {
    name: "ID",
    selector: (row) => row.id,
  }, 
   {
    name: "nickname",
    selector: (row) => row.nickname,
  },  
  {
    name: "name of the user",
    selector: (row) => row.Users.name, // ERROR: Property 'name' does not exist on type 'string'
  },
];
0 Answers
Related