Today I learned
Missusing useEffect
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 Opens in new tab and what the alternatives are. So, good bye useEffect?
His key takeaways were the following:
- the default behaviour of
useEffect
is an infinite loop useEffect
is not for effectsuseEffect
is not a lifecycle hookuseEffect
is not a state setteruseEffect
should actually be calleduseSynchronize
, 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 via Email Opens in new tab.
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