I have the following state in React:
const [counter, setCounter] = useState({foo: 1, bar: 1});
and I have data like
const data = [{who: "foo", otherVal: "bla"}, {who: "bar", otherVal: "bla"}];
If I remove an object from the data array, I want to decrease the counter by 1 related to the who
value of the deleted object.
If {who: "foo", otherVal: "bla"}
gets removed, I want to decrease the foo
key of the counter
because who === "foo"
. But In my app I don’t know that foo
is foo
or bar
is bar
. I must use counter[data.who]
somehow to update my state.