Skip to content

Instantly share code, notes, and snippets.

@apackin
Last active July 17, 2020 19:28
Show Gist options
  • Save apackin/364853c8718d4692269e0f841943c9bd to your computer and use it in GitHub Desktop.
Save apackin/364853c8718d4692269e0f841943c9bd to your computer and use it in GitHub Desktop.
FancyTextSubmit with input refocus
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