Last active
September 29, 2023 22:35
-
-
Save Klerith/0b900641fa2b156021093f658db6279c 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
Que grande que sos Fernando 🤯... El mejor profesor que he tenido, pero por mucho. Esa voz 😍, esa metodología 😎, ese sentido del humor 😉. Un saludo desde Cuba y el que no conoce a React, a cualquier framework le reza jajajaja