News for hackers. Stuff that matters.
Re:Making Sense of React Server Components by cjcenizal on Wednesday September 06, 2023 @02:06PM (#37408759)
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

Re:Making Sense of React Server Components by consilient on Wednesday September 06, 2023 @02:15PM (#37408891)
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.

Re:Making Sense of React Server Components by paulddraper on Wednesday September 06, 2023 @02:26PM (#37409080)
tl;dr Don't use useEffect if there is an alternative.

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

Re:Making Sense of React Server Components by Scarblac on Wednesday September 06, 2023 @04:06PM (#37410568)
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.