Skip to content

Instantly share code, notes, and snippets.

@SoyRol4ndo
Forked from Klerith/useForm.tsx
Created September 22, 2023 12:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SoyRol4ndo/477c3e82dd4197f59de564a7398d860e to your computer and use it in GitHub Desktop.
Save SoyRol4ndo/477c3e82dd4197f59de564a7398d860e 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