Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve documentation on setError #1065

Open
NullDivision opened this issue May 8, 2024 · 1 comment
Open

Improve documentation on setError #1065

NullDivision opened this issue May 8, 2024 · 1 comment

Comments

@NullDivision
Copy link

Currently there are several blind spots and inconsistencies in the documentation for the setError function.

  1. The error argument (second arg) for the function (named FieldError in the docs but ErrorOption in the TS types) is inconsistent. The docs say the type property is required while the TS type has it marked as optional
  2. There is no indication as to what FieldError.type is used for other than an identifier. Unfortunately it seems that not setting the type property fails to merge nested errors (eg. setError('users.0.firstName', { message: 'MSG1' }) followed by setError('users.0', { message: 'MSG2' }) only the second message would be available.
  3. The description for FieldError.types is sparse. Does it set the message to be used in case of built-in errors? Does it apply multiple messages to allow for granular access?
  4. The description mentions "manually set one or more errors" but it's not really discussed how we could set more errors (unless this ties in with point 3). There is a section called "Multiple Errors" in the examples however it gets called for every error individually meaning that the function always sets exactly one error at a time.

It would be nice to avoid confusion on how to best set errors and avoid pitfalls like the one mentioned in point 2.

@bluebill1049
Copy link
Member

would you like to send a PR on improve the doc?

@bluebill1049 bluebill1049 transferred this issue from react-hook-form/react-hook-form May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants