Skip to content

Instantly share code, notes, and snippets.

@itsmacr8
Created October 12, 2023 15:23
Show Gist options
  • Save itsmacr8/c9c8f9c4ec868e1ef76bb6ac4d1e7725 to your computer and use it in GitHub Desktop.
Save itsmacr8/c9c8f9c4ec868e1ef76bb6ac4d1e7725 to your computer and use it in GitHub Desktop.
How to use useRef hook basic example.
import { useRef } from 'react';
function App() {
const formInputRef = useRef(null)
const focusInput = () => {
formInputRef.current.focus();
}
return (
<>
<h1>Using useRef hook to access underlying DOM</h1>
<input ref={formInputRef} type="text" />
<button onClick={focusInput}>Focus input</button>
</>
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment