DOM props and forms

DOM ref prop

Attach an object ref to a host element to access the node after commit. React clears the object ref when the node is removed. Use an event handler for focus rather than reading or changing the node during render.

Formal Syntax & Structure

react syntaxreact
ref={inputRef}

Working Example

Example Snippetreact
import { useRef } from 'react';export default function App() { const inputRef = useRef(null); return <><label>Tool<input ref={inputRef}/></label><button type='button' onClick={() => inputRef.current?.focus()}>Focus tool field</button></>; }
React Reference