reactjs / reactjs/react.dev

Docs: Clarify the behavior of useEffect with non-primitive dependencies in the Hooks documentation

Open
#8,156 4 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

Issue Body (Example):
🗣 Area of Concern: The documentation section for the useEffect hook currently explains the dependency array primarily using primitive values (e.g., numbers, strings). However, the common pitfall of including non-primitive values (objects or arrays) directly in the dependency array (which causes the effect to run on every render due to reference change) is not explicitly highlighted or given a clear warning/solution.

📝 Proposed Solution/Enhancement:

Add a small section or a highlighted "Note on Non-Primitives" to the useEffect page.

Provide a code example demonstrating the infinite loop/excessive-rerender issue when using an object literal ({}) or array literal ([]) inside the dependency array.

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 useEffect page in the Hooks documentation and read its current explanation of dependency arrays. Add a short note about object and array dependencies, including the requested code example, then verify that the documentation clearly explains the reference-change behavior and intended solution.

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
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.