Skip to content

Instantly share code, notes, and snippets.

@Gallevy3313
Last active November 9, 2021 13:17
Show Gist options
  • Save Gallevy3313/5d1241f359867de058bd3b58a85c1b70 to your computer and use it in GitHub Desktop.
Save Gallevy3313/5d1241f359867de058bd3b58a85c1b70 to your computer and use it in GitHub Desktop.
nested forms
import { useForm } from 'react-hook-form';
const useNestedForm = (options) => {
const { handleSubmit: internalSubmit, ...rest } = useForm(options);
const handleSubmit = (onSubmit) => (e) => {
e.preventDefault();
internalSubmit(onSubmit)(e);
e.stopPropagation();
};
return {
handleSubmit,
...rest,
};
};
export default useNestedForm;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment