isValid is sometimes false despite no errors

See original GitHub issue

Describe the bug I sometimes get isValid = false despite having no visible errors and errors object being an empty object ({})

To Reproduce I do not yet have a reproducable sandbox, but I already found a code piece that might be the problem. Please see additional context

Expected behavior isValid should always reflect what the errors object contains (e.g. isValid = Object.keys(errors).length === 0)

Desktop (please complete the following information):

  • OS: Windows 10 202001
  • Browser: Microsoft Edge
  • Version: 86.0.621.0 (Official build) canary (64-bit)

Additional context The problematic line could be this code piece here: https://github.com/react-hook-form/react-hook-form/blob/03216edb0b29bae631fb752e6ec612111d82798d/src/useForm.ts#L341 which triggers revalidation but without providing an isValid parameter as the 4th parameter. Hence this line https://github.com/react-hook-form/react-hook-form/blob/03216edb0b29bae631fb752e6ec612111d82798d/src/useForm.ts#L218 will resolve in !!isValid which essentially means !!undefined === false.

AFAIK the problem only appears on async filled inputs (inputs that get their value via an api request).

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:55 (38 by maintainers)

github_iconTop GitHub Comments

12reactions
bluebill1049commented, Nov 5, 2021

formState is wrapped with a Proxy to improve render performance and skip extra logic if the specific state is not subscribed to. Therefore make sure you invoke or read it before a render in order to enable the state update.

https://react-hook-form.com/api/useform/formstate

const { isValid } = methods.formState;

console.log(isValid);
6reactions
bymoecommented, Dec 8, 2022

Why is this closed when the issue still exists?

Read more comments on GitHub >

github_iconTop Results From Across the Web

'isValid' is always false - Stack Overflow
The loop is occurring when isValid is true , but stops when it is false . You can try it out here. Entering...
Read more >
React Hook Form - validation isValid - CodeSandbox
React Hook Form - validation isValid by github0013 using react, react-dom, react-hook-form, react-scripts, yup.
Read more >
ModelState.IsValid is always false - MSDN - Microsoft
I am struggling with one error. I have copied my files and pasted below. ModelState.IsValid is always showing false, even though I have ......
Read more >
Client-side form validation - Learn web development | MDN
Client-side form validation sometimes requires JavaScript if you want to ... considered to be valid, or false if it fails any constraint.
Read more >
Common issues and solutions - mypy 0.991 documentation
Statically typed code is often identical to normal Python code (except for type ... This gives no error even though a.split() is “obviously”...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found