ant design Form vs 내 Form
나만의 공구 컴포넌트가 있으면 어떨까?!
캡슐화
Radix의 asChild props 참고… 어캐 내부 구현했누????
import { useFormik } from 'formik';
const useCustomFormWithFormik = (initialValues, onSubmit) => {
const formik = useFormik({
initialValues: initialValues,
onSubmit: onSubmit,
});
return {
values: formik.values,
handleChange: formik.handleChange,
handleSubmit: formik.handleSubmit,
};
};
export default useCustomFormWithFormik;
import { useForm } from 'react-hook-form';
const useCustomFormWithReactHookForm = (initialValues, onSubmit) => {
const { register, handleSubmit, setValue } = useForm({
defaultValues: initialValues
});
const handleChange = (event) => {
setValue(event.target.name, event.target.value);
};
return {
values: register,
handleChange: handleChange,
handleSubmit: () => handleSubmit(data => onSubmit(data)),
};
};
export default useCustomFormWithReactHookForm;