custom hook
Your own function whose name starts with use and that calls other hooks, packaging stateful logic so several components can reuse it.
In more detail
Each component calling a custom hook gets its own independent state; hooks share logic, not data. Good hooks return intent-revealing actions, such as toggle and setTrue, rather than raw setters, and keep returned functions stable with useCallback.
Examples
useFocusTrap(active, containerRef) traps Tab inside a dialog and restores focus on unmount.function useToggle(initial = false) { ... return { value, toggle, setTrue, setFalse }; }Related terms
- React hook — A function whose name starts with use, such as useState or useEffect, that lets a React component keep state or run side work.
- Rules of Hooks — The two rules for hooks: call them only at the top level, never in conditions, loops or nested functions, and only from React components or custom hooks.
- useCallback — The React hook that returns the same function object between renders until one of its dependencies changes.
- tuple — An ordered, fixed-length group of values in which each position can have its own meaning and type.
Taught in
- Headless Architecture: State vs Presentation Separation — Design Systems & Component Engineering
- Compound Component Patterns: Context Sharing & Internal State — Design Systems & Component Engineering
- Focus Management: Trapping, Restoration & Focus Rings — Design Systems & Component Engineering
- Compound Components: Inversion of Control with Context — React 19 & Modern Component Architecture
- Higher-Order Components And Render Props: Tradeoff Analysis — React 19 & Modern Component Architecture
- Slot Patterns And Headless UI Architecture in React — React 19 & Modern Component Architecture
- Rules of Hooks: Call Order, Hook Lists, And Fiber Storage — React 19 & Modern Component Architecture
- Custom Hook Composition: Encapsulating Reactive Logic — React 19 & Modern Component Architecture
- useSyncExternalStore: Tearing-Free Store Subscriptions — React 19 & Modern Component Architecture
- Creating Event Listener Hooks with Clean Teardown Logic — React 19 & Modern Component Architecture