-
-
Save joskid/37250f7a15d1c69d872add3f67e41955 to your computer and use it in GitHub Desktop.
Text Input using react hooks with a custom hook: useFormInput
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 { useState } from 'react' | |
const Form = () => { | |
const name = useFormInput('Name') | |
return ( | |
<> | |
<input {...name} /> | |
</> | |
) | |
} | |
function useFormInput(initialValue) { | |
const [value, setValue] = useState(initialValue) | |
function handleChange(e) { | |
setValue(e.target.value) | |
} | |
return { | |
value, | |
onChange: handleChange | |
} | |
} | |
export default Form |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment