useRef for DOM Access

useRef is used to reference DOM elements or persist mutable values across renders without causing a re-render.

import React, { useRef } from 'react';

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

  const handleClick = () => {
    inputRef.current.focus();
  };

  return (
    <>
      
      
    
  );
}

Perfect for accessing or modifying DOM nodes directly or storing instance variables.

← PrevNext →