I want to add an object to the state array.
I want to add an object {user.uuid,user.id} to the state array using the spread syntax,
I want to add an object {user.uuid,user.id} to the state array. But I get an error and can't add any value to the state.
If anyone knows how to solve this problem, please let me know.
const [id, setId] = React.useState<[{uuid: number; id: number}]>([]);
useEffect(() => {
if (id === null) {
users.map((user) => setId([...id, {user.uuid, user.id}]));
}
}, [users]);
I would like to create such an array.
[
{ uuid:sadsa
id:1
},
{ uuid:dadsad
id:2
},
{ uuid:jihji
id:3
},
{ uuid:mokok
id:4
},
]