Created
April 13, 2019 09:21
-
-
Save ohansemmanuel/4149234498cb1062656f0f0703b94c78 to your computer and use it in GitHub Desktop.
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
const AccessDOM = () => { | |
const textAreaEl = useRef(null); | |
const handleBtnClick = () => { | |
textAreaEl.current.value = | |
"The is the story of your life. You are an human being, and you're on a website about React Hooks"; | |
textAreaEl.current.focus(); | |
}; | |
return ( | |
<section style={{ textAlign: "center" }}> | |
<div> | |
<button onClick={handleBtnClick}>Focus and Populate Text Field</button> | |
</div> | |
<label | |
htmlFor="story" | |
style={{ | |
display: "block", | |
background: "olive", | |
margin: "1em", | |
padding: "1em" | |
}} | |
> | |
The input box below will be focused and populated with some text | |
(imperatively) upon clicking the button above. | |
</label> | |
<textarea ref={textAreaEl} id="story" rows="5" cols="33" /> | |
</section> | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment