Ref vs State
Concept Check Medium
Question
When should you use useRef instead of useState?
Hint
Think about whether the value should affect the UI.
Explanation
Use useRef when you need a value that persists across renders but doesn't need to trigger a re-render when it changes — like a timer ID, a DOM reference, or a 'has mounted' flag. If the value should affect what's displayed, use useState so React re-renders on change.
Related Resources
Related Lessons
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.