Using defaultValues containing null causes an error #4091
Replies: 3 comments 6 replies
-
- return <Controller {...props} defaultValue="" as="input" />;
+ return <Controller {...props} as="input" />; you don't need defaultValue there, because you already defined defaultValues at useForm. |
Beta Was this translation helpful? Give feedback.
-
Another workaround is to use prop "render" of Controller to set default empty string on attribute "value" of input. Working sample: https://codesandbox.io/s/sparkling-pine-dolzg?file=/src/TextField.js |
Beta Was this translation helpful? Give feedback.
-
first time it is getting null in defaultvalue. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Problem
Setting defaultValues which contain some null values and a Controller component produces an error in the console:
The null values are received from the api response.
Codesandbox link
https://codesandbox.io/s/suspicious-mahavira-zvlvo
Screenshots

I'm using custom input controls that prevent the rendering when receiving a
null
value. Are there ways to avoid setting the values to null from the defaultValues? Setting therender
property instead ofas
in the Controller component may solve the problem, but it will requires manual configuration of the input component.Beta Was this translation helpful? Give feedback.
All reactions