useeffect update when state changes code example
Example 1: react useeffect on change props
useEffect(() => console.log('value changed!'), [props.isOpen]);
Example 2: useeffect on update
const isInitialMount = useRef(true);
useEffect(() => {
if (isInitialMount.current) {
isInitialMount.current = false;
} else {
// Your useEffect code here to be run on update
}
});