useRef Value
Predict Output Easy
Question
What does this code print?
Code
function App() {
const r = useRef(10);
r.current = 20;
return <p>{r.current}</p>;
}
// What renders?
Hint
ref.current can be mutated directly.
Explanation
useRef(10) creates a ref with initial current=10. Setting r.current=20 updates it. The paragraph renders 20. Changing ref.current does not trigger re-render, but the current render shows the updated value.
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.