react-hook-form: issue: handle global error in forms

Is your feature request related to a problem? Please describe. when I get response after submitting a form, I get two types of errors: a) field related errors, which can be handled by setError b) some global errors, like user not found. there is no place for this kind of errors in react-hook-form

Describe the solution you’d like there can be a field starting with dangle (_) to used as global error for the form.

Describe alternatives you’ve considered Now I use a custom field named _error, but typescript keeps complaining about it, as there is no _error field in my inputs. another workaround was to use a local state.

Additional context in redux-form we could use _error field for global errors. and it’s handled nicely providing a prop named error.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 51
  • Comments: 21 (14 by maintainers)

Most upvoted comments

I’m willing to contribute to this specific issue, but the question is how we should handle it. My solution is to add _error as a reserved field for the global error.

Any feature request goes through community up-voting the feature to see if the feature is in demand before it goes into development

todo: need to include async default values error handling.

this issue was closed as completed, but folks are still talking about it. If it’s not done, then shouldn’t it be reopened?

The feature is tracked on the project board and was closed as an issue for maintainer’s convenience

Hm… what about the fact that it’s pretty common to do

handleSubmit(data => updateEntry(data).then(res => success(res)).catch(err => fail(err)))

Meaning, if you use .then().catch(), the API can return an entry object, which is gonna be returned