useRef in React

From the React Hooks cheat sheet · Context & Refs · verified Nov 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
💡 Read/write .current in effects or handlers, not during render
✅ Use for DOM elements, timers, subscriptions
📌 React 19: ref callbacks can return a cleanup function

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