3 ms·
This page[0] lists many situations in which useEffect shouldn’t be used. Some might seem counter-intuitive. [0] https://react.dev/learn/you-might-not-need-an-e
by cjcenizal 3y ago
This page[0] lists many situations in which useEffect shouldn’t be used. Some might seem counter-intuitive.
[0] https://react.dev/learn/you-might-not-need-an-effect https://react.dev/learn/you-might-not-need-an-effect
- consilient 3y agoThat's not a bunch of separate caveats, it's a few principles illustrated with lots of examples. - Don't use effects for things that aren't genuinely effectful - Put finnicky state management stuff in reusable utils instead of re-implementing it from primitives over and over again. Neither is React-specific.
- paulddraper 3y agotl;dr Don't use useEffect if there is an alternative. That's a bunch of examples where there are good alternatives.
- Scarblac 3y agoIn particular that it's OK to directly call setState inside functional components was a surprise to me (when I read that some months ago), it does make things simpler.