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.
In more detail
Hooks can only be called at the top level of a component or of another hook. Headless libraries package behaviour as custom hooks, such as a useFocusTrap that returns what a dialog needs.
Related terms
- React — A JavaScript library for building user interfaces out of components, functions that return a description of what to show.
- useEffect — The React hook for running side work, such as adding listeners or changing document.body, after a component renders.
- useId — The React hook that generates a unique ID string that is stable across renders and matches between server and browser.
- controllable state hook — A hook that lets one component work both controlled and uncontrolled, using the parent's value when given and its own state otherwise.
- TanStack Query — A library that fetches, caches and refreshes server data in frontend apps, and runs changes to it as mutations.
- Orval — A tool that reads an OpenAPI document and generates typed TypeScript API clients and TanStack Query hooks.
- useState — The React hook that adds a state variable to a component and returns the current value with a function to change it.
- Client Component — A component whose code is also sent to the browser so it can use state, effects and event handlers.
- 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.
- custom hook — Your own function whose name starts with use and that calls other hooks, packaging stateful logic so several components can reuse it.
- hook list — The ordered list React stores on each fiber, holding one record for every hook the component called during render.
- 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
- Type-Safe Client Generation: Orval & Automated SDKs — Production Full-Stack Engineering
- Optimistic UI Architecture: Cache & Rollback Protocols — Production Full-Stack Engineering
- Server Components: Async Execution & Constraints — Next.js 15 & Modern App Router Architecture
- Client Components: use client & Hydration Models — Next.js 15 & Modern App Router Architecture
- Templates vs Layouts: Remounting & Page Transitions — Next.js 15 & Modern App Router Architecture
- Error Boundaries: Nested error.tsx & Reset Logic — Next.js 15 & Modern App Router Architecture
- Async Data Fetching: Parallel Requests & Preloading — Next.js 15 & Modern App Router Architecture
- Action State: useActionState & Optimistic Form UI — Next.js 15 & Modern App Router Architecture
- Component Purity: Pure Functions, Idempotence And Side Effects — React 19 & Modern Component Architecture
- State with useState: Immutability And Asynchronous Batching — React 19 & Modern Component Architecture
- Complex State with useReducer: State Machines And Action Types — React 19 & Modern Component Architecture
- useRef Mechanics: DOM References And Mutable Persistent State — React 19 & Modern Component Architecture
- useContext in Depth: Scoping, Consumer Subscription Costs — React 19 & Modern Component Architecture
- 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
- Tuples: Fixed Length, Labeled Elements And Variadic Tuples — Production TypeScript
- Why Generics: Functions, Identities And Type Variables — Production TypeScript
- Modern Decorators: Stage 3 Standards And Class Metadata — Production TypeScript
- The Spine Artifact: Generating Typed Models From OpenAPI — Production TypeScript