Hooks are functions that let function components use state, effects, context, refs, and more. Introduced in React 16.8, they are now the standard way to add behavior to components. This lesson previews every major hook in this course.
What Are Hooks?
Hooks start with use — useState, useEffect, useContext, etc. Call them at the top level of function components or custom hooks, never inside loops, conditions, or nested functions.
The rules of hooks exist because React relies on call order to associate state with components. Breaking the rules causes bugs that are hard to diagnose.
useState manages data; useEffect syncs with external systems like document.title.
Rules of Hooks
✓ Call hooks at top level of function components or custom hooks
✓ Call hooks in the same order every render
✗ Do not call hooks inside if/for/nested functions
✗ Do not call hooks in class components
✗ Do not call hooks in event handlers
Only call hooks from React function components or custom hooks.
ESLint plugin eslint-plugin-react-hooks enforces the rules automatically.
Custom hooks extract reusable stateful logic — they call other hooks.
Each hook solves a specific category: state, effects, memoization, context.
Built-in Hooks Overview
The hooks covered in this course and their roles.
Hook
Purpose
useState
Local state
useEffect
Side effects after render
useRef
Mutable ref, DOM access
useMemo / useCallback
Performance memoization
useReducer
Complex state transitions
useContext
Read context value
useId
Stable unique IDs for a11y
Hooks vs Class Lifecycle
Hooks compose behavior vertically in one function instead of spreading it across lifecycle methods. Related logic stays together — fetch + cleanup in one effect instead of split across mount/unmount.
Custom Hooks Preview
When you find yourself copying the same state + effect combo, extract a custom hook like useLocalStorage or useFetch. Custom hooks share logic, not UI.