Skip to main content

What happens if you forget dependencies in useEffect?

Entry React
Quick Answer Without all dependencies listed, the effect captures stale values from its first render (a stale closure). The effect runs but uses old data รขโ‚ฌโ€ leading to bugs that are hard to trace. ESLint's exhaustive-deps rule catches this. In React 18+, running effects twice in Strict Mode also surfaces these issues.

Answer

The effect runs after every render, potentially causing infinite loops or unnecessary API requests.
S
SugharaIQ Editorial Team Verified Answer

This answer has been peer-reviewed by industry experts holding senior engineering roles to ensure technical accuracy and relevance for modern interview standards.

Want to bookmark, take notes, or join discussions?

Sign in to access all features and personalize your learning experience.

Sign In Create Account

Source: SugharaIQ

Ready to level up? Start Practice