Skip to content

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

@Lokesh9106

Description

@Lokesh9106

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

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions