useRef in React

From the React Hooks cheat sheet · Context & Refs · verified Jul 2026

useRef

Mutable refs and DOM access

javascript
// DOM reference
const inputRef = useRef(null)
<input ref={inputRef} />
inputRef.current.focus()

// Mutable value (doesn't trigger re-render)
const countRef = useRef(0)
countRef.current++                     // No re-render

// Keep value between renders
const previousValue = useRef(undefined)
useEffect(() => {
  previousValue.current = value
})
⚠️ .current changes don't trigger re-renders
💡 Perfect for storing previous values
✅ Use for DOM elements, timers, subscriptions

Continue with React Hooks

Save the full cheat sheet or work through every related task.

More React tasks

Back to the full React Hooks cheat sheet