๐ŸŒ
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
Which made me eventually run into useRef. 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
Understanding React's useRef Hook
Nice, I really appreciate you working through the problem step by step and arriving at the current solution. Itโ€™s usually how I end up teaching it in person and with any luck this might help me skip a step next time I need to catch somebody up when theyโ€™re struggling to transition from classes to hooks. More on reddit.com
๐ŸŒ r/reactjs
12
177
August 17, 2020
How to replace useState with useRef and be a winner
Can I ask you a question, what's the difference between this and just having a variable declared at the top of the file and just using whatever value is in it next render? More on reddit.com
๐ŸŒ r/reactjs
68
252
October 18, 2021
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ reactjs โ€บ react-js-useref-hook
ReactJS useRef Hook - GeeksforGeeks
Clicking the button increases the count by 1 and updates both the current and previous counts. Direct DOM Manipulation: You can directly access and manipulate DOM elements without triggering a re-render. Persisting Values Across Renders: Use useRef to store values (such as previous state values) that should persist across renders without triggering unnecessary updates.
Published ย  January 22, 2026
๐ŸŒ
Wisdom Geek
wisdomgeek.com โ€บ development โ€บ web-development โ€บ react โ€บ understanding-the-useref-react-hook
Understanding the useRef React hook - Wisdom Geek
October 11, 2023 - If the component were to re-render, the object created by useRef would be persisted. The one created using createRef would point to a new object. If you want to look at another example of this in a practical example, you can check our previous post on detecting a click outside a React component using the useRef hook.
๐ŸŒ
Hygraph
hygraph.com โ€บ blog โ€บ react-useref-a-complete-guide
React useRef() - A complete guide | Hygraph
January 21, 2026 - Unlike state variables managed ... component's behavior. When React encounters a useRef() Hook, it returns a plain JavaScript object with a single property: current....
๐ŸŒ
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.
๐ŸŒ
Kinstaยฎ
kinsta.com โ€บ home โ€บ resource center โ€บ blog โ€บ react โ€บ understanding the useref hook in react
Understanding the useRef Hook in React
2 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.
๐ŸŒ
Frontendeng
frontendeng.dev โ€บ blog โ€บ 20-what-is-useRef-in-react-and-how-to-use-it
What is useRef in react and how to use it correctly | Front End Engineering
September 24, 2023 - useRef is a React hook that allows you to obtain a reference to the underlying DOM object associated with a React component. It is particularly useful when you need to make direct changes to the DOM object without relying on other React primitives.
Find elsewhere
๐ŸŒ
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?

๐ŸŒ
Dmitri Pavlutin
dmitripavlutin.com โ€บ react-useref
React useRef() Hook Explained in 3 Steps - Dmitri Pavlutin
April 3, 2023 - useRef(initialValue) is a built-in React hook that accepts one argument as the initial value and returns a reference (aka ref).
๐ŸŒ
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 ...
๐ŸŒ
DEV Community
dev.to โ€บ nibble โ€บ what-is-useref-hook-and-how-do-you-use-it-5emo
What is useRef hook and how do you use it? - DEV Community
July 15, 2020 - For example if you want to access an input element after it has been mounted to the DOM, instead of using document.getElementById, document.querySelector or any other method for selecting DOM elements like in vanilla javascript, you can use useRef hook. This is illustrated in the example below. import React from "react"; import ReactDOM from "react-dom"; const App = (props) => { const inputRef = React.useRef(null); React.useEffect(() => { console.log(inputRef.current); inputRef.current.focus(); }, []); return ( <form> <input type="text" placeholder="Enter Name" name="name" ref={inputRef} /> </form> ); }; const root = document.getElementById("root"); ReactDOM.render(<App />, root);
๐ŸŒ
Felix Gerschau
felixgerschau.com โ€บ how to use react's useref() hook | felix gerschau
How to use React's useRef() hook | Felix Gerschau
The last use case for useRef that I want to show you is holding a reference to the previous state. In my example on codepen, I've created a component that updates the name variable with an input field. To hold a reference to the last value of name, we can simply use the useEffect hook and make it execute on every change. In the callback, we then update the reference. const prevNameRef = React.useRef(''); React.useEffect(() => { prevNameRef.current = name; }, [name]);
๐ŸŒ
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).
๐ŸŒ
React
react.dev โ€บ learn โ€บ referencing-values-with-refs
Referencing Values with Refs โ€“ React
You wonโ€™t need them often. A ref is a plain JavaScript object with a single property called current, which you can read or set. You can ask React to give you a ref by calling the useRef Hook.
๐ŸŒ
Mimo
mimo.org โ€บ glossary โ€บ react โ€บ useref-hook
React useRef Hook: Syntax, Usage, and Examples
... Become a full-stack developer. Learn HTML, CSS, JavaScript, and React as well as NodeJS, Express, and SQL ... Build modern web apps with React. Learn components, hooks, state management, and React patterns ... To use useRef, call the hook and assign the result to a variable.
๐ŸŒ
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 ...
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.

๐ŸŒ
ui.dev
ui.dev โ€บ useref
Understanding React's useRef Hook - Fireship
It accepts an initial value as its first argument and it returns an object that has a current property (which will initially be set to whatever the initial value was). From there, anything you add to current will be persisted across renders. The most popular use case for useRef is getting access to DOM nodes. If you pass the value you get from useRef as a ref prop on any React element, React will set the current property to the corresponding DOM node.
๐ŸŒ
Thoughtspile
thoughtspile.github.io โ€บ 2021 โ€บ 10 โ€บ 18 โ€บ non-react-state
How to replace useState with useRef and be a winner
October 18, 2021 - It rarely results in visible bugs, but makes your components more complex and slows them down. ... See when state can be safely replaced with a ref (spoiler: you only need state if your JSX depends on it, or to trigger use*Effect); Learn a few optimizations for performance-critical cases. Let's first spend a minute reflecting on what's so special about react state, and what types of non-react state exist, and how they're so different, but still useful.