liveBook · Manning

useCallback

As explained in React Hooks in Action: With Suspense and Concurrent Mode

useCallback is a React Hook that memoizes a function so its identity can remain stable across renders until specified dependencies change.

When a component passes a function to children, defining that function during rendering creates a new identity each time. useCallback lets React preserve the identity until dependencies change. section 6.5 section 6.5.2

Call useCallback with a function and dependency list. React returns the cached function on subsequent renders, then redefines and returns it when a dependency changes. Stable functions can prevent effects from repeating unnecessarily and help memoized components avoid updates caused only by changed function identity. section 6.5.2 section 6.6

Stable booking selection

A BookablesView component wraps updateBookable in useCallback with an empty dependency list, then passes the stable function to BookablesList. The dependent effect can stop endlessly refetching bookables data. section 6.5.2

const stableFunction = useCallback(funtionToCache, dependencyList);

Use the compact signature to see the cached function and dependency-list roles. section 6.5.2

How React Hooks in Action: With Suspense and Concurrent Mode covers it

How deep it goes
Explains caching, dependency-triggered redefinition, effects, and memoized components without descending into React internals.
Examples
Uses a BookablesView updater passed to BookablesList and an effect that otherwise refetches endlessly.
What it assumes
Assumes familiarity with components, rendering, props, state, and effects while reinforcing updater functions and dependency lists.
What you can do after
Apply it via a dependency list to preserve function identity across renders and control dependent updates.
How it connects
Connects function identity with props, useEffect, useState, useReducer, and memoized components.

Also explained in

Compare how 2 books explain useCallback →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of React Hooks in Action: With Suspense and Concurrent Mode. The section links point to the parts of the book it draws on.