Created
September 26, 2020 16:57
-
-
Save adamjarling/852e1ba7f764cba8bfba6aa883b6fd7d to your computer and use it in GitHub Desktop.
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
/** | |
* Higher order helper function which wraps a component w/ React Hook Form | |
* @param {React Component} WrappedComponent to pass into | |
* @param {*} restProps any other remaining props | |
* @returns {React Component} | |
*/ | |
export function withReactHookForm(WrappedComponent, restProps) { | |
const HOC = () => { | |
const methods = useForm(); | |
return ( | |
<FormProvider {...methods}> | |
<WrappedComponent {...restProps} /> | |
</FormProvider> | |
); | |
}; | |
return HOC; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment