reactjs use state and use effect code example
Example 1: useeffect with cleanup
useEffect(() => {
//your code goes here
return () => {
//your cleanup code codes here
};
},[]);
Example 2: componentdidupdate in hooks
const App = props => {
const didMountRef = useRef(false)
useEffect(() => {
if (didMountRef.current) {
doStuff()
} else didMountRef.current = true
}
}