Created
March 5, 2020 21:33
-
-
Save markodayan/a6c34ab0b06d4b4d64297c3ec614d9f1 to your computer and use it in GitHub Desktop.
Custom Hooks in React (Form Input State Management)
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'; | |
export const useForm = initialValues => { | |
const values, setValues[ = useState(initialValues); | |
return [ | |
values, | |
e => { | |
setValues({ | |
...values, | |
[e.target.name]: e.target.value | |
}); | |
} | |
]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment