Last active
July 17, 2020 19:28
-
-
Save apackin/364853c8718d4692269e0f841943c9bd to your computer and use it in GitHub Desktop.
FancyTextSubmit with input refocus
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 FancyTextSubmit() { | |
const inputRef = useRef(null); | |
const onButtonClick = () => { | |
// `current` points to the mounted text input element | |
inputRef.current.focus(); | |
}; | |
return ( | |
<div> | |
<input ref={inputRef} type="text" /> | |
<button onClick={onButtonClick}>Focus the input</button> | |
</div> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment