Monday, December 09, 2019

The match condition of react useEffect

From https://lukaszmakuch.pl/post/react-hooks-oops-part-2-effect-runs-multiple-times-with-the-same-dependencies/


useEffect(fn, deps);
 
fn is the function, and deps is an array of values it depends on. Every time the component renders, React checks if all the values in the deps array are still the same. If any of them has changed since the last render, fn is run again.

So, in the deps array, any one of variables changed, then the function fn inside useEffect run.