useeffect react version code example
Example 1: useeffect react
useEffect(() => {
// code goes here
return () => {
// cleanup code codes here
};
},[]);
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
}
});