will cause an infinite render loop, because errorMessages is a nested object that is recreated on every render, so even though errorMessages is marked as a dependency in useEffect hook used internally by this library, it will use === comparison, always return false and cause re-render.
It can be easily fixed by defining error messages outside of the component:
Maybe it could be mentioned in the README, or maybe there's some way to handle it by the library itself, or maybe everyone who is more familiar with React hooks knows about it already ;)
This might be obvious for people who have more experience with React hooks, but code like this:
will cause an infinite render loop, because
errorMessages
is a nested object that is recreated on every render, so even thougherrorMessages
is marked as a dependency inuseEffect
hook used internally by this library, it will use===
comparison, always returnfalse
and cause re-render.It can be easily fixed by defining error messages outside of the component:
Maybe it could be mentioned in the README, or maybe there's some way to handle it by the library itself, or maybe everyone who is more familiar with React hooks knows about it already ;)