Refs and the DOM
useRef for values that shouldn't re-render, reaching real DOM nodes, ref as a prop, useImperativeHandle, portals and wrapping non-React widgets.
Most of the time React owns the page: you describe the screen and React changes the DOM. But sometimes you need to step outside that model. You need to remember a timer id without redrawing anything, put the cursor in a text box, scroll a list to the newest message, measure how wide a box is, or hand a real DOM element to a chart library that knows nothing about React. Refs are React's escape hatch for exactly these jobs.
In this phase you'll learn useRef and how a ref differs from state, how to attach refs to DOM elements (one element, or a whole list of them with callback refs and a Map), how React 19 lets you pass ref to your own components as a normal prop (and how older code did it with forwardRef), how useImperativeHandle exposes a small, safe API instead of a whole DOM node, how portals render a modal or tooltip somewhere else in the DOM while staying in your React tree, and how to wrap non-React code with a ref and an effect, using flushSync when the DOM must update right now.
Refs are powerful because React doesn't watch them. That is also why they are easy to misuse. Every topic shows the rule for when a ref is the right tool, and the bug you get when it isn't.
Practise this phase
Hands-on exercises: write the code, see your page live, and press Check to have it tested automatically.