When updating a state, react does not re-render the screen. Moreover, the use effect is not called.
When clicking on the "change" button, react does not seem to want to re-render with the new values. Also, the use effect is not called.
const [identity, setIdentity] = useState([{id: 1, name: "Lucas"}, {id: 2, name: "Jean"}]);
const [show, setShow] = useState(false);
useEffect(() => {
console.log("UPDATE");
}, [identity]);
But when another state changes, the screen is updated.
You can try this CodeSandBox: https://codesandbox.io/s/nifty-frog-su3m30?file=/src/App.js
I have a hunch, maybe I'm not using the right method to change the value of my object.
function handleChange(evt) {
const toEdit = identity;
const index = toEdit.findIndex(predicate => predicate.id = 1);
toEdit[index] = {...toEdit[index], name: "Michel"}
console.log({index, toEdit});
setIdentity(toEdit);
}
