question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

clearing errors object when to return errors: {} from a resolver

See original GitHub issue

Is your feature request related to a problem? Please describe.

  1. mode: onChange
  2. use validationResolver
  3. have errors in more than one inputs
  4. validate all inputs by one of the inputs, and return errors: {} in the resolver

Currently errors: {} doesn’t clear const {errors} = userForm() this errors object entirely. resolver only updates the errors for the specific input you change.

Describe the solution you’d like

I would like to see errors object being cleared to {} by giving errors: {} from a resolver.

Describe alternatives you’ve considered N/A

Additional context

https://codesandbox.io/s/react-hook-form-validationresolver-errors-j2iyu

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
bluebill1049commented, Mar 17, 2020

good point @github0013 i will re-open this issue and update the documentation, so others people aware of this issue and the reason behind this decision.

1reaction
bluebill1049commented, Mar 16, 2020

ok @github0013 i have completely my investigation. Short story, i think we will keep what we got for now. Let me explain the reason behind. Feel free to leave your thoughts as well.

The way we trigger re-render is based on error appear/disappear: https://github.com/react-hook-form/react-hook-form/blob/master/src/useForm.ts#L563 which is one of the performance enhancement for this library. If an error is persist then there is no need to re-render, so does when an error gets resolved, and it’s cheap to running against a single error at a time. We can invest into errors object comparison, but then it’s not efficient at least with my estimation for now. so for conclusion, we will keep as it for now.

let me know if this make sense.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error handling - Apollo GraphQL Docs
The unwrapResolverError function can remove the GraphQLError wrapping from a resolver error or return the error unaltered if it isn't from a resolver....
Read more >
Resolve or Die - Error Handling Strategies for Loading Data in ...
If you are using a Route Resolver, and it encounters an unhandled exception, the route will not resolve, and your page will simply...
Read more >
A Definitive Guide to Handling Errors in JavaScript - Kinsta
Getting tripped up by errors in your JavaScript? We'll show you how to tame those errors so you can get back to developing...
Read more >
Error handling with promises - The Modern JavaScript Tutorial
In the task an error is thrown form inside the promise and promise is never settled neither with a resolve nor reject. The...
Read more >
Best practice to return ApolloErrors from Nexus resolver
I'm currently struggeling with returning errors from my resolvers ... to return either the success value (like a user object) or an error....
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