- I’m still reading A complete guide to
useEffect
. I keep needing to read and re-read sections of it .
If your mental model is “dependencies let me specify when I want to re-trigger the effect”, this example might give you an existential crisis.
-
Yes this is exactly how I’m feeling right now
-
Sometimes it is important that your
useEffect
runs only once, so the emptyuseEffect
is still valid approach (I think!) -
The techniques to not lie about deps is very interesting.
- the functional updater form of
setState
looks very handy.
- the functional updater form of
-
useReducer
is usually a good idea to keep logic and state clean when inside auseEffect
it decouples Updates from Actions.useReduce
is the cheatmode of hooks. avoid putting your reducer inside a component , but do so if you need to read props from the component. -
If you only use some functions inside an effect, move them directly into that effect: