Skip to content

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

Description

@jagadeeshkaruturi11

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions