📡 You're offline — showing cached content
New version available!
Quick Access
Tutorials React Modern Development useRef

useRef

5 min read
useRef creates a mutable value that does not cause re-renders. Attach to a DOM element with ref={myRef} and access it as myRef.current. Also used to store timer IDs and track previous values between renders.

useRef Hook

import { useRef } from "react";

function TextInput() {
  const inputRef = useRef(null);

  function focusInput() {
    inputRef.current.focus();
  }

  return (
    <>
      
      
    
  );
}

// useRef for mutable values (no re-render)
const timerRef = useRef(null);
timerRef.current = setInterval(fn, 1000);