How to Synchronize React with Browser APIs
Browser APIs such as events, observers, and timers live outside React. Use useEffect to connect to them and a cleanup function to disconnect.
Build modern UIs with React
Browser APIs such as events, observers, and timers live outside React. Use useEffect to connect to them and a cleanup function to disconnect.
A stale closure captures state from an old render and keeps using it after the value changes. Learn why it happens and how to fix it.
useEffectEvent reads the latest props and state from inside an Effect without re-running it. Learn how to separate events from Effects.
useRef stores a mutable value that survives between renders without triggering a new render. Learn how it works and when to reach for it.
Use useRef to point at an input element and call focus() on it, so a button or an Effect can move keyboard focus to the field.
useState triggers a re-render when it changes and useRef does not. Use state for what the UI shows and refs for what only event handlers and Effects need.
Track the previous value of a prop or state variable with a useRef plus Effect pattern, and learn when the official render-time alternative is better.
Pass a ref from a parent to a child by treating ref as a regular prop in React 19, and forward it down to the DOM node you want to expose.
Use useImperativeHandle to replace the DOM node exposed through a ref with a custom object, so a parent can call only the methods you allow.
useId returns a unique ID string for linking labels, hints, and inputs with accessibility attributes, even when a component renders many times.
Move keyboard focus into a modal when it opens, restore it on close, trap Tab inside, and focus the heading when a route changes.
Use an aria-live region to announce content changes to screen reader users, choosing polite or assertive and announcing the right amount.