Skip to content

Conversation

@SaifUrRehman2k
Copy link

@SaifUrRehman2k SaifUrRehman2k commented Dec 2, 2025

Docs: Clarify useEffect() dependency pitfall with objects and arrays

Closes: #8156

Description:

This PR addresses issue #8156 by clarifying the behavior of the useEffect() dependency array when non-primitive values (objects or arrays) are used.

Problem:

The existing documentation doesn't explicitly warn developers about the common pitfall where non-primitive dependencies, which create a new reference on every render, can cause the effect to run on every render (or cause infinite loops).

Solution:

Instead of adding a redundant, separate section, this PR now integrates a concise warning into the 'Specifying reactive dependencies' section of useEffect.md.

@github-actions
Copy link

github-actions bot commented Dec 2, 2025

Size changes

📦 Next.js Bundle Analysis for react-dev

This analysis was generated by the Next.js Bundle Analysis action. 🤖

This PR introduced no changes to the JavaScript bundle! 🙌

@SaifUrRehman2k SaifUrRehman2k changed the title Docs: Defined the behavior of useEffect with non-primitive dependencies Docs: Clarify useEffect non-primitive dependency pitfall Dec 2, 2025
@SaifUrRehman2k SaifUrRehman2k deleted the hooks/useEffect-dependencyArray branch December 10, 2025 05:45
@SaifUrRehman2k SaifUrRehman2k restored the hooks/useEffect-dependencyArray branch December 10, 2025 10:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant