Created
April 13, 2019 09:24
-
-
Save ohansemmanuel/4a60c0efd14d2380eeb942fb259026e3 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 HoldStringVal = () => { | |
const textAreaEl = useRef(null); | |
const stringVal = useRef("This is a string saved via the ref object --- ") | |
const handleBtnClick = () => { | |
textAreaEl.current.value = | |
stringVal.current + "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" | |
}} | |
> | |
Prepare to see text from the ref object here. Click 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