Skip to content

Instantly share code, notes, and snippets.

@asaumet230
Last active June 27, 2023 20:41
Show Gist options
  • Save asaumet230/d6309d525536ca7933feea40f75d1af9 to your computer and use it in GitHub Desktop.
Save asaumet230/d6309d525536ca7933feea40f75d1af9 to your computer and use it in GitHub Desktop.
Custom Hook UseForm( )
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