Skip to content

Instantly share code, notes, and snippets.

@kyleshevlin
Created January 24, 2020 16:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kyleshevlin/4a9e7f29cead36f4329e2dd22b72860a to your computer and use it in GitHub Desktop.
Save kyleshevlin/4a9e7f29cead36f4329e2dd22b72860a to your computer and use it in GitHub Desktop.
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