Created
July 31, 2016 14:50
-
-
Save rbrtsmith/c9ad843e7cef3d17677f3fd8c8aefac9 to your computer and use it in GitHub Desktop.
Despite common opinion it is possible to use refs inside of a functional React 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
const CommentForm = () => { | |
let author, text; | |
const submitForm = e => { | |
e.preventDefault(); | |
console.log(author.value); | |
console.log(text.value); | |
}; | |
return ( | |
<form onSubmit={submitForm}> | |
<input type="text" ref={node => author = node} placeholder="Name" /> | |
<input type="text" ref={node => text = node} placeholder="Comment" /> | |
<button type="submit"> | |
submit | |
</button> | |
</form> | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This totally works, as proven by the console.logs!