Today I learned

Missusing useEffect

Edit this Post Opens in new tab

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 effects
  • useEffect is not a lifecycle hook
  • useEffect is not a state setter
  • useEffect should 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 Opens in new tab or 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