Hacker News new | past | comments | ask | show | jobs | submit login

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




That'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.


In 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.


tl;dr Don't use useEffect if there is an alternative.

That's a bunch of examples where there are good alternatives.




Consider applying for YC's W25 batch! Applications are open till Nov 12.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: