Refs and the DOM Escape Hatch
Understand refs as React's deliberate escape hatch for imperative DOM access, and where the boundary between declarative and imperative code should sit.
React's entire model is declarative — you describe what the UI should look like given the current state, and React handles the imperative work of updating the actual DOM to match. Refs are the officially sanctioned escape hatch for the specific cases where imperative access genuinely is needed: focusing an input, measuring an element's size, integrating a non-React library that expects a real DOM node, or triggering an animation.
Refs are like a building's emergency exit: the normal, everyday flow of people (declarative rendering) goes through the main doors according to clear signage and rules, but the emergency exit (a ref) exists deliberately for the specific, narrower set of situations that genuinely need to bypass that normal flow — using the emergency exit as your regular daily entrance defeats the purpose of having an orderly main entrance at all.