liveBook · Manning

Dependency array

A dependency array is an array passed to a React effect or memoization Hook that specifies values whose changes trigger recomputation or rerunning.

How 3 Manning books explain it

React Hooks in Action: With Suspense and Concurrent Mode

A dependency array is an array passed to useEffect that determines when the effect is run again based on dependency changes.

How it is used
Controls when useEffect side effects run as components render, rerender, mount, and unmount.
How deep it goes
Explains comparison-driven scheduling, empty and populated arrays, cleanup order, and warnings, without descending into React internals.
Examples
Uses window resizing, local-storage user selection, user fetching, and bookables loading to demonstrate dependency choices.
What you can do after
Apply dependency arrays to schedule effects, persist state, fetch initial data, and prevent repeated event-listener registration.

Read how React Hooks in Action: With Suspense and Concurrent Mode explains dependency array →

React in Depth

A dependency array is the optional second argument to a React effect or memoization hook that determines when its computation is rerun.

How it is used
Controls effect reruns and memoized computations while balancing correct updates against unnecessary work.
How deep it goes
Distinguishes omitted, empty, and nonempty arrays; explains referential equality, stable-value exceptions, and maintenance pitfalls.
Examples
Uses employee-list filtering, render tracking, and a deletion callback with a stable state setter.
What you can do after
Apply it in React hooks to select rerun conditions and diagnose missing or needlessly changing dependencies.

Read how React in Depth explains dependency array →

React Quickly, Second Edition

A dependency array is an array passed to a React effect Hook that specifies values whose changes determine when the effect runs again.

How it is used
Controls when React effects and their cleanup functions respond to component mounts, renders, unmounts, and selected value changes.
How deep it goes
Explains skipped, empty, and value-based arrays with lifecycle examples, but defers detailed implementation internals.
Examples
Uses data loading, timers, dialog-close tracking, browser titles, active flags, and unmount cleanup.
What you can do after
Apply it via React's useEffect hook to schedule effects and cleanup at selected component lifecycle points.

Read how React Quickly, Second Edition explains dependency array →

Related concepts

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.