If you’ve been learning React, you’ve likely mastered useState and useEffect. But then you run into useRef, and suddenly things feel… a bit weird.
It doesn’t update the screen. It doesn't trigger re-renders. It feels like it’s breaking the "React rules." But here is the secret: useRef is your component’s private, persistent storage.
Let’s break down what it actually does, why it’s useful, and how to use it without the headache.
What useRef Actually Is
At its core, useRef gives you a place to store a value that:
stays the same between renders
can be changed anytime
does not cause a re-render when it changes
That’s it.
const myRef = useRef(initialValue);
React gives you an object that looks like this:
{ current: initialValue }
The important part is .current.
That’s where the value lives.
React creates this object once and keeps returning the same one on every render.
Why useRef Exists at All
You might wonder: "Why not
Discussion
Jump in and comment!
Get the ball rolling with your comment!