reactjs / reactjs/react.dev

Further explanation about why side-effects should be limited to useEffect

Open
#2,607 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
11.8k
Forks
7.9k
Avg merge
1d 11h
Merged PRs (30d)
11

Description

There are multiple recommendations about when side-effects are okay and when they are not okay; it is difficult to memorize them all, so it would be helpful if some further explanation is added explaining exactly why useEffect should be exclusively used for side effects e.g.
https://github.com/reactjs/reactjs.org/blob/master/content/docs/hooks-effect.md#example-using-classes-example-using-classes

For traditional life-cycle hooks, the reasoning is that some of them might be called multiple times before the render is committed; is the same applicable to hooks?

Thanks!

p.s. This comment seems relevant:
https://github.com/reactjs/reactjs.org/issues/302#issuecomment-345445888

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked Hooks Effect documentation section and compare its discussion of class lifecycle methods with the current guidance on side effects and useEffect. Update the documentation with a clear explanation of why side effects belong in useEffect and address whether the same repeated-call concern applies to hooks; done means the recommendation is understandable without memorizing separate rules.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, react
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.