Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

590
Views
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.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!