Created
August 17, 2019 19:29
-
-
Save hacker0limbo/57a877a2110d1526d3f332cbaa24440a to your computer and use it in GitHub Desktop.
custom hooks from Dan Abramov's speech
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 useFormInput = initialValue => { | |
const [value, setValue] = useState(initialValue) | |
const handleChange = e => { | |
setValue(e.target.value) | |
} | |
return { | |
value, | |
onChange: handleChange | |
} | |
} | |
const FormInput = props => { | |
const name = useFormInput('') | |
return ( | |
<input {...name} /> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment