- Carried on reading some more of A Complete Guide to useEffect (man it’s a long blog!)
- Thinking about react in effects helps you understand why we might get into unintended re-renders.
- Every re-renders is an function execution, which folds in values in the current known state. e.g when you run a
setTimeout
with a variable, then change the variable before thesetTimeout
has executed, thesetTimeout
‘remembers’ the old value still! useState
lets you persist state between refreshes/effects. Remember when you update a value withuseState
this cause a re-renders!useRef
lets you mutate values without casing a causing re-rendersdeps
in auseEffect
is a way to let React know the exact dependancies the component needs to “watch” for changes to then refresh. But don’t ever lie about deps as a workaround to prevent a refresh. This can cause unintended consequences.