Created
May 1, 2023 22:08
-
-
Save programarivm/75e42876e4fa20b09c86559eae3c2fb6 to your computer and use it in GitHub Desktop.
Select an element
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function TextInputWithFocusButton() { | |
const inputEl = useRef(null); | |
const onButtonClick = () => { | |
// `current` points to the mounted text input element | |
inputEl.current.focus(); | |
}; | |
return ( | |
<> | |
<input ref={inputEl} type="text" /> | |
<button onClick={onButtonClick}>Focus the input</button> | |
</> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment