TypeError: Cannot read properties of null (reading 'control') #7942
-
Hello, I don't understand why It can be nice to create molecule where we can give Error are not thrown if I do something like that:
|
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 3 replies
-
can you share a codesandbox? |
Beta Was this translation helpful? Give feedback.
-
The |
Beta Was this translation helpful? Give feedback.
-
In my case, I was getting this error even though it was wrapped in a
|
Beta Was this translation helpful? Give feedback.
-
Your solution of adding optimizeDeps: { exclude: ['react-hook-form'] } is not working for me. The code is running fine in the browser but while testing the component using vitest I am receiving this TypeError: Cannot read properties of null (reading 'control'). code: https://codesandbox.io/p/sandbox/vitest-react-hook-form-24ckqc |
Beta Was this translation helpful? Give feedback.
-
Found the solution at last. It doesn't matter whether I add optimizeDeps: { exclude: ['react-hook-form'] } in vite.config.js or not. Changing the import for useFormContext from 'react-hook-form' to 'react-hook-form-mui' fixes the issue when FormContainer is used from react-hook-form-mui |
Beta Was this translation helpful? Give feedback.
The
control
is optional, so that havingFormProvider
up the React tree, theController
(or any other control dependent hook) can pull thecontrol
value from the form'sContext
if non provided via the prop.