Skip to content

Instantly share code, notes, and snippets.

@angel190884
Forked from Klerith/useForm.tsx
Created July 21, 2021 22:58
Show Gist options
  • Select an option

  • Save angel190884/af4880da24db210379b1f6caeb9ca790 to your computer and use it in GitHub Desktop.

Select an option

Save angel190884/af4880da24db210379b1f6caeb9ca790 to your computer and use it in GitHub Desktop.
Hook para el manejo de formularios
import { useState } from 'react';
export const useForm = <T extends Object>( initState: T ) => {
const [state, setState] = useState( initState );
const onChange = ( value: string, field: keyof T ) => {
setState({
...state,
[field]: value
});
}
return {
...state,
form: state,
onChange,
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment