Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

more informative error message when useField is being used in a component that's not a child of <Form> #396

Open
skwakman opened this issue Apr 30, 2021 · 0 comments

Comments

@skwakman
Copy link

skwakman commented Apr 30, 2021

What would you like to be added:
When placing a custom component that uses Unform's useField hook, this component is required to be a child of a <Form> component. If it's not, a rather cryptic error message is thrown in the console.

To reproduce:

  1. go to the live example of the Basic Form in the documentation here
  2. in the live code example, replace the <Form> element with a <div> (be sure to also change the closing tag)
  3. The following error will be thrown: 'TypeError: t is undefined', where t could be another letter depending on minification.

Why is this needed:
While this error is triggered by a developer mistake (why use the Input when there's no parent form), but it's an easy mistake to make. And because this error is so cryptic, it takes way longer to figure out what I did wrong than it needs to be.

Instead of thowing this error, replace it with something more descriptive. For example: useField called by a component that is not a child of a <Form>. Please make sure this component is a child of a <Form>.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant