Created
January 24, 2020 16:49
-
-
Save kyleshevlin/4a9e7f29cead36f4329e2dd22b72860a 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
import React from 'react' | |
export default SimpleForm () { | |
const [value, setValue] = React.useState('') | |
const handleSubmit = e => { | |
e.preventDefault() | |
console.log(value) | |
} | |
const handleChange = e => { | |
setValue(e.target.value) | |
} | |
return ( | |
<form onSubmit={handleSubmit}> | |
<input onChange={handleChange} type="text" value={value} /> | |
// Did you know that the default type of a button is "submit" and that you don't need | |
// to add an onClick handler to this type for the form to submit. Bonus, you get | |
// keyboard access, too. Hitting enter will submit the form. | |
<button type="submit">Submit</button> | |
</form> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment