React DOM

Focus with a ref

Use the browser focus method from an event or appropriate post-commit synchronization.

Formal Syntax & Structure

react syntaxreact
inputRef.current?.focus();

Working Example

Example Snippetreact
<button onClick={() => inputRef.current?.focus()}>Focus</button>
React Reference