Reputation: 53
The useEffect run in the first and when the parameter change is run another one, I don't want the use effect run until the parameter change only. How?
Upvotes: 1
Views: 1325
Reputation: 676
You can use hook like this to check it's first mount/render
const useDidMountEffect = (func, deps) => {
const didMount = useRef(false);
useEffect(() => {
if (didMount.current) func();
else didMount.current = true;
}, deps);
}
Next you can check result ot useDidMountEffect
Upvotes: 1