Skip to content
Learn Netverks

Lesson

Step 20/36 56% through track

effect-dependencies

Effect dependencies

Last reviewed May 28, 2026 Content v20260528
Track mode
client_react
Means
In-browser React TSX
Reading
~1 min
Level
intermediate

This lesson

This lesson teaches Effect dependencies: the concepts, APIs, and habits you need before advancing in React.

Side effects (fetch, subscriptions, timers) must be modeled explicitly—this lesson prevents infinite loops and stale closures.

You will apply Effect dependencies in contexts like: SPAs, dashboards, design-system-driven products, and React Native mobile apps.

Write TypeScript/TSX, click Run in browser—React 18 loads from CDN, JSX compiles in the tab, UI renders in the preview root, and printOutput feeds the terminal.

When you can explain the previous lesson's ideas without copying starter code.

The dependency array tells React which values the effect reads. When any dependency changes, React re-runs the effect after the next render.

Rules of thumb

  • Include every prop and state variable used inside the effect
  • Stable setters from useState do not need to be listed (React guarantees stability)
  • Objects and arrays as dependencies compare by reference—memoize or depend on primitives

Stale closures

Missing dependencies can show outdated values—the effect “closes over” old state. ESLint’s react-hooks/exhaustive-deps rule catches most mistakes in real projects.

Important interview questions and answers

  1. Q: Empty deps vs no deps?
    A: [] runs once per mount; omitting the array runs after every render.
  2. Q: Infinite loop symptom?
    A: Effect sets state that is in its dependency array without a guard—fix logic or split effects.

Self-check

  1. Why does changing userId require listing it in deps?
  2. What happens if you pass a new object literal in deps every render?

Tip: ESLint react-hooks/exhaustive-deps warns about stale closures—fix deps or refactor, do not silence blindly.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs in your browser in a sandboxed frame. Backend runners appear when this track’s profile allows them.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • Missing dep bug?
  • Empty deps meaning?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump