formstate errors not updating across components #13204
Replies: 2 comments
|
bump |
|
This is the Destructure what you need at the top so the Proxy registers the subscription: import { useFormContext, useFormState } from 'react-hook-form';
export const SaveBar = ({ handleSubmit }: Props) => {
const { control } = useFormContext();
const { errors, isDirty, dirtyFields } = useFormState({ control });
if (!isDirty || !Object.keys(dirtyFields ?? {}).length) return null;
return (
<div>
<h2>You have unsaved changes!</h2>
<pre>{JSON.stringify(errors, null, 2)}</pre>
</div>
);
};
|
Uh oh!
There was an error while loading. Please reload this page.
Hello, I have a savebar component which I aim to display some of the errors in my form.
I am using the following code:
When there is a form error, the error appears. However, when the user fixes the form error the error state is not updated in the
form.formstate.errorsproperty. How am I supposed to get up to date form state errors?I have enabled
revalidateModetoonChangebut this had no effect.All reactions