All hooks must be called inside function component bodies. Calling hooks outside a component throws an error.
Returns a stateful value and a function to update it.
const [count, setCount] = useState(0);
setCount(5); // Direct value
setCount(prev => prev + 1); // Functional updaterAlternative to useState for complex state logic.
const [state, dispatch] = useReducer(
(state, action) => { switch(action.type) { ... } },
{ count: 0 }
);
dispatch({ type: 'increment' });Runs side effects after render. Returns an optional cleanup function.
useEffect(() => {
const id = setInterval(tick, 1000);
return () => clearInterval(id);
}, []);Like useEffect but fires synchronously after DOM mutations, before paint.
Fires before DOM mutations. Designed for CSS-in-JS libraries.
Reads the current value from the nearest matching Provider.
const theme = useContext(ThemeContext);Returns a mutable ref object that persists across renders.
const inputRef = useRef<HTMLInputElement>(null);Customizes the instance value exposed to parent refs via forwardRef.
Memoizes an expensive computation. Recomputes only when deps change.
const sorted = useMemo(() => items.sort(compareFn), [items]);Returns a memoized callback. Equivalent to useMemo(() => callback, deps).
const handleClick = useCallback(() => setCount(c => c + 1), []);Wraps a component to skip re-renders when props are shallowly equal.
Generates a unique ID stable across server and client renders.
const id = useId(); // ":l0:", ":l1:", etc.Marks state updates as non-urgent transitions.
Defers a value update to avoid blocking urgent updates.
Subscribes to an external data source.
Displays a label in DevTools for custom hooks. No-op in production.