I have an state that has an array of objects. I'm stuck trying to update a property of an object inside that array.
const [state, setState] = useState([obj = {key: "x"}, obj = {key: "y"}])
I'm trying to create a handleChange event to control an input element.
So far, I tried the code below where __index is a property that I use as an identifier.
const handleChange = (event) => {
setState((prevState) => [
...prevState.filter((otherObj) => otherObj.__index !== obj.__index),
(obj = {
...prevState[obj.__index],
description: event.target.value,
}),
]);
};