mount and unmount with hooks code example
Example 1: useeffect with cleanup
useEffect(() => {
//your code goes here
return () => {
//your 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
}
});