Last active
June 27, 2023 20:41
-
-
Save asaumet230/d6309d525536ca7933feea40f75d1af9 to your computer and use it in GitHub Desktop.
Custom Hook 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"; | |
const useForm = ( initialState = {} ) => { | |
const [ values, setValues ] = useState(initialState); | |
// Agregar Valores al Formulario: | |
const handleInputChanges = ( { target } ) => { | |
setValues({ | |
...values, | |
[ target.name ]: target.value | |
}); | |
} | |
// Resetear Valores del Formulario; | |
const reset = ()=> { | |
setValues(initialState); | |
} | |
return [ values, handleInputChanges, reset ]; | |
} | |
export default useForm; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment