Last active
January 2, 2019 05:37
-
-
Save troygoode/833a9265ce42b4d309adc6d77a70b5c3 to your computer and use it in GitHub Desktop.
more Hook goodness
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
import React from 'react' | |
import { useInput } from 'react-hanger' | |
const DEFAULT_NAME_VALUE = 'Troy' | |
const DEFAULT_EMAIL_VALUE = '[email protected]' | |
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