Skip to content

Instantly share code, notes, and snippets.

@troygoode
Last active January 2, 2019 05:37
Show Gist options
  • Save troygoode/833a9265ce42b4d309adc6d77a70b5c3 to your computer and use it in GitHub Desktop.
Save troygoode/833a9265ce42b4d309adc6d77a70b5c3 to your computer and use it in GitHub Desktop.
more Hook goodness
import React from 'react'
import { useInput } from 'react-hanger'
const DEFAULT_NAME_VALUE = 'Troy'
const DEFAULT_EMAIL_VALUE = 'troygoode@gmail.com'
const ExampleForm = () => {
const name = useInput(DEFAULT_NAME_VALUE)
const email = useInput(DEFAULT_EMAIL_VALUE)
const onSubmit = () => {
console.log({
name: name.value,
email: email.value
})
}
return (
<form onSubmit={onSubmit}>
<input placeholder="Name" {...name.bindToInput} />
<input placeholder="Email" type="email" {...email.bindToInput} />
<button type="submit">Submit</button>
</form>
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment