'How to use put an 'empty' value in react-hook-forms defaultValues with Typescript?
I use react-hook-forms with typescript and react native. When I set the defaultValues field in the useForm method I need to have in the beginning empty fields, there is no problem when the field is a string, but I have fields that for example should be a date. When I set the date to undefined I get a warning - fieldname is missing in the 'defaultValue' prop of either its controller or useForm, and when I try to set it to null I get some TypeScript error that the field in defaultValues must be either a Date or undefined, since react-hook-forms DefaultValues type can accept each field as an actual value or undefined.
So basically for each solution I get an error / warning. How can I solve that?
Thanks ahead.
EDIT:
The form data type:
interface FormData {
date: Date;
}
But - the DefaultValue type for this form (this is from react-hook-form) is:
{
date: Date | undefined;
}
EDIT V2:
I found a solution - in my case I used the Controller component defaultValue prop with null and it worked.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
