Skip to content

Instantly share code, notes, and snippets.

@4drian-sanchez
Last active May 11, 2023 00:42
Show Gist options
  • Save 4drian-sanchez/29e51b4a12ddae8fd74968ad1aa55c7e to your computer and use it in GitHub Desktop.
Save 4drian-sanchez/29e51b4a12ddae8fd74968ad1aa55c7e to your computer and use it in GitHub Desktop.
useForm
import { useState } from "react";
export const useForm = (initialForm = {}) => {
const [ formState, setFormState ] = useState( initialForm );
const hundleChange = ({ target: { name, value } }) => {
setFormState({
...formState,
[ name ]: value
});
}
const hundleReset = () => setFormState( initialForm );
return {
...formState,
setFormState,
formState,
hundleChange,
hundleReset,
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment