I have checked the official doc and realised we cannot directly use Hooks inside the class-based component. So, I have tried the HOC method to use react-hook-form with a class-based component.
But this case is also not working in my case.
My HOC Component::
import React from "react";
import { useForm } from "react-hook-form"
export const ClassHookFormWrap = (Component) => {
const form = useForm();
console.log("form", form, Component)
return (props) => {
return <Component form={form} {...props} />;
};
};
My class-based component::
import React from "react";
import { ClassHookFormWrap } from "./ClassHookFormWrap";
class ClassHookForm extends React.Component {
onSubmit = (data) => {
console.log(data);
}
render(){
console.log("this.props", this.props)
return(
<div>Form</div>
)
}
}
export default ClassHookFormWrap(ClassHookForm);
The error I got inside console::
This is a sandbox link I have added a code sample here:: https://codesandbox.io/s/old-monad-7mkxg8?file=/src/App.js:224-237
Is there any way to use this form inside a class-based component?
