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:
- Start typing in input
- Then delete all input to trigger onChange Validation
- 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)
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.errorskeeps input errors anderrorsdoesn’t have them anymore? I’m not sure what theerrorsobject 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!
I encountered a similar problem, in that
errorsobject 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,
formStatedoesn’t haveerrorsfield 🤔Thanks for the issue report, try to use
FormStateas the dep.errorsjust an alias insideformState.