P4.6: Refs and useRef
Sometimes, you need to step outside React's virtual model to interact directly with the real browser DOM. Common examples include:
- Auto-focusing a text input field when a page loads.
- Measuring the size or scroll position of a box.
- Controlling a video or audio playback node.
To do this, we use the useRef Hook.
