-
-
Save SoyRol4ndo/477c3e82dd4197f59de564a7398d860e 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