Today I learned
Today I learned that Reacts
useEffect is not meant for data fetching and is
not a state setter either!
This questions all my best practices I’ve applied over the last years since we got useEffect.
David K. Piano held this amazing talk about our wrong understanding of useEffect ↗ and what the alternatives are. So, good bye useEffect?
His key takeaways were the following:
- the default behaviour of
useEffectis an infinite loop
useEffectis not for effects
useEffectis not a lifecycle hook
useEffectis not a state setter
useEffectshould actually be called
useSynchronize, because it's meant to synchronize React with external systems
I hope you enjoyed this post and learned something new. If you have any questions, feel free to reach out to me on Twitter ↗ or via Email ↗.
If you want to support me, you can buy me a coffee. I would be very happy about it!☕️ Buy me a coffee ☕️
I wish you a wonderful day! Marco