Last active
November 9, 2021 13:17
-
-
Save Gallevy3313/5d1241f359867de058bd3b58a85c1b70 to your computer and use it in GitHub Desktop.
nested forms
This file contains 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 { 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