react useEffect each time component enables code example
Example 1: componentdidupdate in hooks
const App = props => {
const didMountRef = useRef(false)
useEffect(() => {
if (didMountRef.current) {
doStuff()
} else didMountRef.current = true
}
}
Example 2: useeffect react
useEffect(() => {
// code goes here
return () => {
// cleanup code codes here
};
},[]);