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)
Any feature request goes through community up-voting the feature to see if the feature is in demand before it goes into development
published as v7.43.0-next.0
release note: https://github.com/react-hook-form/react-hook-form/releases/tag/v7.43.0-next.0
RFC: https://github.com/react-hook-form/react-hook-form/discussions/9691
todo: need to include async default values error handling.
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
Meaning, if you use
.then().catch(), the API can return an entryobject, which is gonna bereturned