why we use dependcies in react useEffect code example
Example 1: useeffect react
useEffect(() => {
// code goes here
return () => {
// cleanup code codes here
};
},[]);
Example 2: useEffectOnce
import {useEffectOnce} from 'react-use';
const Demo = () => {
useEffectOnce(() => {
console.log('Running effect once on mount')
return () => {
console.log('Running clean-up of effect on unmount')
}
});
return null;
};