- 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
useEffectruns only once, so the emptyuseEffectis still valid approach (I think!) -
The techniques to not lie about deps is very interesting.
- the functional updater form of
setStatelooks very handy.
- the functional updater form of
-
useReduceris usually a good idea to keep logic and state clean when inside auseEffectit decouples Updates from Actions.useReduceis 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: