useRef vs createRef in React: Difference and Trade Off
Explore useRef vs createRef in React with examples. Learn the key differences between useRef and createRef, use cases and when to choose one over the other in React applications
Anuj Sharma
Last Updated Jun 19, 2026

In React, useRef and createRef are two commonly used tools for managing references to DOM elements or values within functional components. While both can achieve similar outcomes, they have distinct differences in terms of usage and behavior.
This blog post will explore the differences between useRef and createRef, their use cases, and provide guidance on when to choose one over the other in React applications.
Table of Content
Difference between useRef vs createRef
Let's start by understanding the fundamental differences between useRef and createRef in React.
createRef()
createRef is a method available in React that allows you to create a ref object to access DOM nodes or React elements within a class component. When you use createRef, React creates a ref object and attaches it to the component instance, which can then be used to reference DOM elements or React components.
class MyComponent extends React.Component {
constructor(props) {
super(props);
this.myRef = React.createRef();
}
render() {
return <div ref={this.myRef}>Hello, World!</div>;
}
}
useRef Hook
useRef is a Hook in React that allows you to create a mutable ref object to store mutable values or references to DOM nodes within functional components. Unlike createRef, useRef does not attach the ref to the component instance. Instead, it returns a mutable ref object that persists across re-renders.
import { useRef } from "react";
const MyComponent = () => {
const myRef = useRef(null);
return <div ref={myRef}>Hello, World!</div>;
};
Key Differences
| Feature | useRef() |
createRef() |
|---|---|---|
| Component Type | Used in Functional Components | Primarily used in Class Components |
| Persistence | Same ref object persists across re-renders | Creates a new ref object on every render |
| Mutability | Mutable object (current can be updated) |
Ref object is managed by React |
| Re-renders | Updating current does not trigger a re-render |
Updating current does not trigger a re-render |
| Lifecycle Usage | Works with Hooks (useEffect, etc.) |
Commonly accessed in lifecycle methods |
| Functional Updates | Can store mutable values across renders | Not intended for storing mutable values |
| Common Use Cases | DOM access, timers, previous values, mutable state | DOM access in class components |
| Example | const inputRef = useRef(null) |
this.inputRef = React.createRef() |
Use Cases
Let's explore some common use cases where you might choose useRef or createRef in your React applications.
useRef Use Cases
- Managing Focus: Keeping track of focused elements and managing focus programmatically.
- Storing Previous Values: Storing previous values for comparison in useEffect hooks.
- Accessing DOM Elements: Referencing and manipulating DOM elements directly within functional components.
createRef Use Cases
- Accessing Child Components: Accessing child components or DOM nodes within class components.
- Integrating with Third-Party Libraries: Interfacing with third-party libraries that require a ref to interact with DOM elements.
- Handling Animations: Managing animations or interactions that rely on direct access to DOM elements.
When to Choose useRef or createRef
The decision to use useRef or createRef depends on the specific requirements of your React application. Here are some guidelines to help you choose between the two:
- Functional Components: If you are working with functional components,
useRefis the preferred choice due to its compatibility with Hooks. - Mutability: If you need a mutable ref that persists across renders and supports functional updates, opt for
useRef. - Class Components: For class components or when direct access to lifecycle methods is required, use
createRef. - Interacting with DOM: When your use case involves direct manipulation of DOM elements, consider using
useReffor functional components orcreateReffor class components.
Final Thoughts
In summary, both useRef and createRef are valuable tools in React for managing references to DOM elements and values. Understanding the differences between the two and knowing when to choose one over the other can help you write more efficient and maintainable React applications. By leveraging useRef and createRef effectively based on your specific requirements, you can enhance the functionality and performance of your React components.
Further Reading
Love this Blog? Share it Now!
Help others discover this resource
A seasoned Sr. Engineering Manager at GoDaddy (Ex-Dell) with over 12+ years of experience in the frontend technologies. A frontend tech enthusiast passionate building SaaS application to solve problem. Know more about me 🚀








