The useRef hook preserves the reference to the DOM element even if it changes, allowing you to access and manipulate it without causing unnecessary re-renders of the component.