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
🌐
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.
🌐
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
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.
🌐
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 ...
🌐
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?

Find elsewhere
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.

🌐
GeeksforGeeks
geeksforgeeks.org › reactjs › react-js-useref-hook
ReactJS useRef Hook - GeeksforGeeks
Here we have a button called ACTION, whenever we click on the button the onClickHandler gets triggered and it focuses the textarea with the help of useRef hook. ... import React, { Fragment, useRef } from 'react'; function App() { const focusPoint = useRef(null); const onClickHandler = () => { focusPoint.current.value = "The quick brown fox jumps over the lazy dog"; focusPoint.current.focus(); }; return ( <Fragment> <div> <button onClick={onClickHandler}> ACTION </button> </div> <label> Click on the action button to focus and populate the text.
Published   5 days ago
🌐
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.
🌐
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.
🌐
React
legacy.reactjs.org › docs › refs-and-the-dom.html
Refs and the DOM – React
These new documentation pages teach ... the DOM with Refs · useRef · forwardRef · Refs provide a way to access DOM nodes or React elements created in the render method....
🌐
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.
🌐
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
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 ...
🌐
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).
🌐
ui.dev
ui.dev › useref
Understanding React's useRef Hook - Fireship
As you probably guessed by now, the ability to persist a value across renders without causing a re-render is so fundamental that React comes with a built-in Hook for it called useRef.
🌐
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....
🌐
Kinsta®
kinsta.com › home › resource center › blog › react › understanding the useref hook in react
Understanding the useRef Hook in React
3 weeks ago - The useRef Hook serves two main purposes: storing mutable values that do not cause a re-render when updated and storing references to DOM elements. Let’s explore how it works in more detail.
🌐
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.