-
-
Save angel190884/af4880da24db210379b1f6caeb9ca790 to your computer and use it in GitHub Desktop.
Hook para el manejo de formularios
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 = <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