Hey guys i am currently new at TypeScript and i am trying to have a state value that conatins only objects . At the moment i have an array of objects like this :
[{ Ananas: "A", Banana: "B" , Citroen: "C"}]
, but the ultimate goal would be to have something like this :
{ Ananas: "A", Banana: "B" , Citroen: "C"}
I was defining my initial state like this
const [selectValue, setSelectValue] = useState<Array<string>>([]);
And now i try something like this , but i think is not the correct way to have initial state of objects only
const [selectValue, setSelectValue] = useState({});
My update function is as simple as that
const handleChange = (e: any) => {
setSelectValue((selectValue: any) => {
const newSelectValue = [...selectValue];
if (!newSelectValue[0]) newSelectValue[0] = {};
newSelectValue[0] = { ...newSelectValue[0], [e.target.value]: e.target.name };
return newSelectValue;
});
};
But as i said from above i want to update the state value to contain only objects and not an array of objects . So i wonder how can i do that. Thanks upfront