-
-
Save 4drian-sanchez/29e51b4a12ddae8fd74968ad1aa55c7e to your computer and use it in GitHub Desktop.
useForm
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 = (initialForm = {}) => { | |
const [ formState, setFormState ] = useState( initialForm ); | |
const hundleChange = ({ target: { name, value } }) => { | |
setFormState({ | |
...formState, | |
[ name ]: value | |
}); | |
} | |
const hundleReset = () => setFormState( initialForm ); | |
return { | |
...formState, | |
setFormState, | |
formState, | |
hundleChange, | |
hundleReset, | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment