Last active
March 5, 2020 21:59
-
-
Save markodayan/43a7e7c95b1e234d968b9f3fce2b37b6 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