useRef Purpose
Question
What is useRef primarily used for?
Hint
useRef changes do not cause re-renders.
Explanation
useRef returns a mutable ref object whose .current property persists across renders. Unlike state, changing .current does not trigger a re-render. Common uses: accessing DOM elements (const inputRef = useRef(null); <input ref={inputRef} />), storing mutable values like timers or previous values, and keeping instance-like data. Refs are the escape hatch for values that do not need to drive rendering.
Related Resources
Related Lessons
- useRef
Learn useRef.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.