react-hook-form: errors object from useFormContext doesn't seem to update properly

Describe the bug I’m not sure if this is intended ✨

I’m trying to use the errors object from the FormProvider/Context. I want to use it to update a global state outside of the FormProvider. So I want to use the ‘errors’ object as a dependency in my useEffect. However if doesn’t look like the errors object is changing? or it is but not causing a reaction

To Reproduce Steps to reproduce the behavior:

  1. Start typing in input
  2. Then delete all input to trigger onChange Validation
  3. See Error state NOT change to Error: true

Codesandbox link (Required) https://codesandbox.io/s/react-hook-form-validation-onchange-errors-update-88zd8?file=/src/index.js

Expected behavior The errors object from useFormContext should update and trigger re-renders

Screenshots the CSB should be enough

Desktop (please complete the following information):

  • OS: MAC IOS
  • Browser chrome
  • Version 84.0.4147.135 (Official Build) (64-bit)

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 17 (6 by maintainers)

Most upvoted comments

Ok, I’ll try to isolate my issue and try to reproduce it on CSB then. If I didn’t come back here, then I couldn’t repro it. 😁 Thank youu!!

@bluebill1049 @changyeamoon ^created a new issue for the endless re-render just now, managed to repro it on CSB 😃

Hi all,

@bluebill1049 can you explain why formState.errors keeps input errors and errors doesn’t have them anymore? I’m not sure what the errors object is about right now in v6…

Also, I’ve noticed, that trigger() doesn’t return errors object anymore… I can provide some samples later on. A lot of huge changes regarding migration that make a big headache for our developers…

Thank you!

Thanks for the issue report, try to use FormState as the dep. errors just an alias inside formState.

I encountered a similar problem, in that errors object seems to be mutated and not re-created, when new errors appear, so it doesn’t trigger re-render on my component.

According to typings, formState doesn’t have errors field 🤔

Thanks for the issue report, try to use FormState as the dep. errors just an alias inside formState.