Created
December 21, 2020 04:47
-
-
Save MinthangML/f41a35bccfb253f62350cfbcb2d538b5 to your computer and use it in GitHub Desktop.
useRef in functional component
This file contains hidden or 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
import React, { useRef } from "react"; | |
const CustomTextInput = () => { | |
const textInput = useRef(); | |
focusTextInput = () => textInput.current.focus(); | |
return ( | |
<> | |
<input type="text" ref={textInput} /> | |
<button onClick={focusTextInput}>Focus the text input</button> | |
</> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment