liveBook · Manning

Custom hook

A custom hook is a developer-defined JavaScript function that composes React Hooks to encapsulate reusable stateful or effectful component logic.

How 4 Manning books explain it

React Quickly, Second Edition

A custom hook is a developer-defined function that composes React Hooks to provide reusable component logic.

How it is used
Packages component logic for reuse or moves it out of a component to make the UI easier to read.
How deep it goes
Defines what qualifies as a custom hook and works through state, context, form, and reducer extractions.
Examples
Shows a countdown toggle, form handler, context accessor, counter, and reducer-backed loader; also proposes a timer reset refactor.
What you can do after
Build it from scratch to share hook-based logic or simplify a component while preserving the rules of hooks.

Read how React Quickly, Second Edition explains custom hook →

React Hooks in Action: With Suspense and Concurrent Mode

A custom hook is a reusable function that encapsulates React hook logic and can be called by multiple function components.

How it is used
Simplifies function components by encapsulating reusable state, context access, subscriptions, side effects, and data fetching.
How deep it goes
Explains extraction, composition, parameters, return shapes, cleanup, and Rules of Hooks, while deferring broader centralized data management.
Examples
Demonstrates useDocumentTitle, useRandomTitle, useUsers, useFetch, useWindowSize, useUser, and useLocalStorage.
What you can do after
Build reusable hooks that extract component logic, compose other hooks, manage effects, and expose focused values or actions.

Read how React Hooks in Action: With Suspense and Concurrent Mode explains custom hook →

React in Depth

A custom hook is a JavaScript function that follows React hook conventions to encapsulate reusable stateful or effectful component logic.

How it is used
Uses custom hooks to organize component logic and define focused interfaces between presentation and data layers.
How deep it goes
Works through single-hook and composed-hook extractions, application-facing APIs, and a direct test rather than hook internals.
Examples
Uses a radio group, user profile, application data API, and keyboard-state test as concrete examples.
What you can do after
Build it from scratch by extracting focused component logic, then apply React Testing Library’s renderHook to test a shared hook.

Read how React in Depth explains custom hook →

Build AI-Enhanced Web Apps

A reusable React function that composes built-in hooks to encapsulate stateful behavior and related logic.

How it is used
Encapsulates chat state management and API submission so React components can concentrate on rendering.
How deep it goes
Explains hook structure, state exposure, helpers, side effects, and a concrete submission workflow without covering testing implementation.
Examples
Uses ChatPage, ChatList, messages, loading feedback, and the useChatFormSubmit chat-submission hook.
What you can do after
Apply it via React to isolate reusable stateful behavior and keep component logic maintainable.

Read how Build AI-Enhanced Web Apps explains custom hook →

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.