warran / web /src /hooks /useForm.js
Jessedbrown's picture
add: useForm hook
9a33f8f
Raw History Blame Contribute Delete
355 Bytes
import { useState } from 'react';
export const useForm = (initialValues) => {
const [form, setForm] = useState(initialValues);
const onChange = (event) => {
const { name, value } = event.target;
setForm({ ...form, [name]: value });
};
const resetForm = () => {
setForm(initialValues);
};
return [form, onChange, resetForm];
};