🚀 LEVEL UP TO SENIOR:Unlock 500+ Advanced Practical Challenges & Expert Masterclasses.
🎓 COURSERA PARTNER:Earn professional Google, Meta, and IBM certificates to supercharge your resume.
REFERENCEreact

react Documentation

LOADING ENGINE...

React useRef

Master React components, hooks, and best practices.

useRef

Author

Pascual Vila

Frontend Instructor.

useRef is a hook that allows you to create a mutable reference that persists across renders. It is useful for accessing a DOM element or storing values that do not cause a re-render when they change.

Example of useRef:

          {`import React, { useState, useRef } from "react";
          
          function FocusInput() {
            const inputRef = useRef(null);
            
            const handleClick = () => {
              inputRef.current.focus();
            };
            
            return (
              <div>
                <input ref={inputRef} type="text" />
                <button onClick={handleClick}>Focus Input</button>
              </div>
            );
          }
          
          export default FocusInput;`}