I want to create a dynamic array in typescript in the following format
const display = [
{ id: 1, displayName: "Abc1" },
{ id: 2, displayName: "Abc2" },
{ id: 3, displayName: "Abc3" }
]
I have tried the following codes
const [display, SetDisplay] = useState([])
function createData(id: number, name: string) {
return { id, name };
}
SetDisplay(display.push(createData(1, "Abc1")))
But can not push data into the variable display. Getting error like
Argument of type '{ id: number; result: string; }' is not assignable to parameter of type 'never'.
Any information for resolving this would be helpful.