useRef is like you said different from normal state variables managed with useState in React. While useState is designed to store state that causes re-renders when updated, useRef is designed to store mutable values that persist across renders without causing a re-render.

useRef is useful in the following situations:

  • Accessing DOM elements: It is often used to create references to DOM elements so that you can interact with them directly, e.g., focusing an input element.

  • Storing the previous state: It can store the previous state or value of a variable, which is useful in scenarios where you need to compare the current value with the previous value without causing re-renders.

  • Storing values that don't affect rendering: Sometimes you might need to store values that are not part of the component's render output, e.g., timers, intervals, or subscriptions. In this case, using useRef is more suitable because it doesn't cause a re-render.

The main reason why useRef exists is to provide a way to manage values across renders without causing unnecessary updates. Although you can use a "normal" variable, it will not persist across renders as the component function will be executed again, and the variable will be re-initialized.

In summary, useRef is used for managing values that persist across renders without causing re-renders, while useState is used for managing state that affects the component's output and should cause re-renders when updated. They serve different purposes, and understanding when to use one over the other is essential for writing efficient React components.

Answer from rMonteiro on Stack Overflow
🌐
React
react.dev › reference › react › useRef
useRef – React
React will set the current property back to null when the node is removed from the screen. Read more about manipulating the DOM with refs. 1. Focusing a text input 2. Scrolling an image into view 3. Playing and pausing a video 4. Exposing a ref to your own component · In this example, clicking the button will focus the input: ... import { useRef } from 'react'; export default function Form() { const inputRef = useRef(null); function handleClick() { inputRef.current.focus(); } return ( <> <input ref={inputRef} /> <button onClick={handleClick}> Focus the input </button> </> ); }
🌐
W3Schools
w3schools.com › react › react_useref.asp
React useRef Hook
React Compiler React Quiz React Exercises React Syllabus React Study Plan React Server React Interview Prep React Bootcamp React Certificate ... The useRef Hook allows you to persist values between renders.
Discussions

What is useRef for? When should I use it?

useRef is like a box where you can store something. A number, an object, anything you want.

This value is persisted between renders. So if you save in this box some value, it will be available in the next render.

And unlike useState, changes in your useRef "box" does not trigger a new render.

Some comparisons (not technical):

  • It is similar to useState, but it doesn't triggers a new render.

  • If you come from class components, it is like storing an instance variable (this.value = someValue).

What is it used for?

  1. to store mounted components: <Input ref={myRef} /> so you can later do something. For example, trigger a focus on this element: myRef.current.focus()

  2. To store anything you want (like useState) BUT without triggering a new render.

I wrote about this here.

More on reddit.com
🌐 r/reactjs
4
4
September 3, 2020
reactjs - Why does 'useRef' exist? What's it intended for? - Stack Overflow
Except that useRef not only doesn't cause a render, it also doesn't cause a dependancy trigger... At which point I'm confused and wonder why I should use it at all, because at that point it's a bothersome way of using a normal variable. .current = vs = I thought the whole point of React ... More on stackoverflow.com
🌐 stackoverflow.com
UseState vs. UseRef

I use useRef to store timeout id's so I can cancel them later.

current page and filters sound like thinkgs that should trigger a render though. You certainly show them on page, and the page should change, at least to a loading animation, if you don't have the data on hand.

More on reddit.com
🌐 r/reactjs
14
21
July 15, 2022
I still don't know useRef properly and don't know it's use case
useState - rerenders on change. useRef - doesn't More on reddit.com
🌐 r/reactjs
21
28
July 21, 2022
🌐
Hygraph
hygraph.com › blog › react-useref-a-complete-guide
React useRef() - A complete guide | Hygraph
January 21, 2026 - React assigns the initial value you define to the current property of the returned reference. React will set the value of the useRef to undefined if you don't provide an initial value.
🌐
React
legacy.reactjs.org › docs › hooks-reference.html
Hooks API Reference – React
Essentially, useRef is like a “box” that can hold a mutable value in its .current property. You might be familiar with refs primarily as a way to access the DOM. If you pass a ref object to React with <div ref={myRef} />, React will set ...
🌐
Refine
refine.dev › home › blog › tutorials › understanding the react useref hook
Understanding the React useRef Hook | Refine
October 16, 2024 - The useRef hook takes an initial value of any type as argument and returns an object with a single current property. ... React will set the initialValue you pass to the useRef hook as the value of the current property of the returned ref object.
🌐
Reddit
reddit.com › r/reactjs › what is useref for? when should i use it?
r/reactjs on Reddit: What is useRef for? When should I use it?
September 3, 2020 -

Hi! I'm currently learning the hooks i haven't used before, useRef is specifically hard for me to understand, What is it for? and when should I use it? I tried reading the docs over and over again and watching web dev simplified and Ben awads vids but I still don't understand it. Can anyone ELI5?

🌐
React
react.dev › learn › referencing-values-with-refs
Referencing Values with Refs – React
Inside your component, call the useRef Hook and pass the initial value that you want to reference as the only argument. For example, here is a ref to the value 0: ... You can access the current value of that ref through the ref.current property.
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › reactjs › react-js-useref-hook
ReactJS useRef Hook - GeeksforGeeks
A ref created with useRef is attached to the textarea, allowing the click handler to access the DOM element and programmatically set focus. ... import React, { Fragment, useRef } from 'react'; function App() { const focusPoint = useRef(null); ...
Published   4 days ago
🌐
Mimo
mimo.org › glossary › react › useref-hook
React useRef Hook: Syntax, Usage, and Examples
Learn how to use the React useRef hook to access DOM elements, store mutable values, and persist data across renders without causing re-renders.
Top answer
1 of 1
16

useRef is like you said different from normal state variables managed with useState in React. While useState is designed to store state that causes re-renders when updated, useRef is designed to store mutable values that persist across renders without causing a re-render.

useRef is useful in the following situations:

  • Accessing DOM elements: It is often used to create references to DOM elements so that you can interact with them directly, e.g., focusing an input element.

  • Storing the previous state: It can store the previous state or value of a variable, which is useful in scenarios where you need to compare the current value with the previous value without causing re-renders.

  • Storing values that don't affect rendering: Sometimes you might need to store values that are not part of the component's render output, e.g., timers, intervals, or subscriptions. In this case, using useRef is more suitable because it doesn't cause a re-render.

The main reason why useRef exists is to provide a way to manage values across renders without causing unnecessary updates. Although you can use a "normal" variable, it will not persist across renders as the component function will be executed again, and the variable will be re-initialized.

In summary, useRef is used for managing values that persist across renders without causing re-renders, while useState is used for managing state that affects the component's output and should cause re-renders when updated. They serve different purposes, and understanding when to use one over the other is essential for writing efficient React components.

🌐
Dmitri Pavlutin
dmitripavlutin.com › react-useref
React useRef() Hook Explained in 3 Steps - Dmitri Pavlutin
April 3, 2023 - In this post you'll learn how to use React.useRef() hook to create persisted mutable values (also known as references or refs), as well as access DOM elements.
🌐
Felix Gerschau
felixgerschau.com › how to use react's useref() hook | felix gerschau
How to use React's useRef() hook | Felix Gerschau
React's useRef hook, short for reference, allows us to persist data across renders without causing the component to rerender.
🌐
Medium
medium.com › @titoadeoye › react-hooks-useref-with-practical-examples-9ce71ad38d73
React Hooks: useRef (With Practical Examples!) | by Tito Adeoye | Medium
February 25, 2024 - In summary, the useRef hook in React is essential for handling mutable values that persist without causing re-renders and useful for interacting directly with the DOM. Unlike state variables, changes to a ref’s current property don't trigger ...
🌐
Codecademy
codecademy.com › docs › react › hooks › useref()
React | Hooks | useRef() | Codecademy
January 3, 2024 - The useRef() hook in React is used to create mutable references to elements or values within functional components.
🌐
ReScript
rescript-lang.org › docs › react › hooks-ref
useRef Hook | ReScript React
React.useRef returns a mutable ref object whose .current record field is initialized to the passed argument (initialValue).
🌐
Leewarrick
leewarrick.com › blog › react-use-effect-explained
React's useEffect and useRef Explained for Mortals | Strings and Things
September 6, 2019 - I imagine it could be a bit of a black eye for React, so perhaps they don’t wish to call it out too loudly. Dan Abramov, however, describes the problem better in his blog and even provides a solution: “Effects always “see” props and state from the render they were defined in. That helps prevent bugs but in some cases can be annoying. For those cases, you can explicitly maintain some value in a mutable ref.” · This was helpful, because it provided a solution in the form of useRef (Thanks Dan!), but it left me in the dark as to how it would help avoid the issue (mostly because I didn’t understand useRef).
🌐
LogRocket
blog.logrocket.com › home › how to use the react useref hook effectively
How to use the React useRef Hook effectively - LogRocket Blog
April 7, 2025 - The useRef Hook works great for handling imperative actions like DOM manipulations. Instead of using JavaScript Web API methods, such as querySelector or getElementById, to select a DOM element in React, we utilize the useRef Hook to hold its ...
🌐
Medium
yosua-halim.medium.com › react-useref-in-3-minutes-e21f7a57432b
React useRef in 3 minutes. Okay, today we will learn how to use… | by Yosua Halim | Medium
May 13, 2022 - This is something you never want to do. in React you always want to do your management through React State and Props instead change using refs. Another use case useRef can do is you can store previous value of your state for example we can add ...
🌐
Smashing Magazine
smashingmagazine.com › 2020 › 11 › react-useref-hook
A Thoughtful Way To Use React’s useRef() Hook — Smashing Magazine
November 19, 2020 - In a React component, `useState` ... functions. In this article, you will find out how to use the `useRef()` hook to keep track of variables without causing re-renders, and how to enforce the re-rendering of React Components....
🌐
React Express
react.express › hooks › useref
useRef
We start by wrapping a value, e.g. 42, with: const myRef = useRef(42). Then, we use myRef.current to access or update the mutable value. All React components can be passed a ref using the ref prop, in which case React will automatically assign the instance of the component, or the underlying DOM node, to myRef.current.