Skip to content

Instantly share code, notes, and snippets.

@adamjarling
Created September 26, 2020 16:57
Show Gist options
  • Save adamjarling/852e1ba7f764cba8bfba6aa883b6fd7d to your computer and use it in GitHub Desktop.
Save adamjarling/852e1ba7f764cba8bfba6aa883b6fd7d to your computer and use it in GitHub Desktop.
/**
* 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