Replies: 4 comments 11 replies
-
at the stage, we don't want to expand the API, perhaps you should |
Beta Was this translation helpful? Give feedback.
-
I understand not wanting to add to the API, but I'm surprised this isn't needed by a lot more people. We also need to check the dirty state when the user clicks the Cancel button and show a yes/no confirmation dialog if they've made changes. This also forces us to rerender the form. Is that really the case? |
Beta Was this translation helpful? Give feedback.
-
I'm wondering about this, too. I want to show an "Undo" button but only have it appear when the form is dirty. I've just started using react-hook-form because it looks great, but this seems to be an annoying little omission. My bad. Just found it: I can use "formState.isDirty". |
Beta Was this translation helpful? Give feedback.
-
I suppose const { isDirty } = useFormState({ control: form.control }); |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I have registered a function with React Router that will ask the user if they want to discard changes or block the route switch. Everything works, but the only way I can see to check the dirty state of the form is to use
which causes the form to be rendered on every input change. If I don't do that, checking
formState.dirty
returnsfalse
since it's bound to the initialformState
object. Is there a way to access the dirty flag on-the-fly via an object or reference that doesn't change and doesn't cause rerenders? PerhapsformState.isDirty()
or something similar?As an example, I store my function above in a reference held in a React Context. This way each route can supply a different function without rerendering the entire application since the reference itself never changes—only the value it holds.
Beta Was this translation helpful? Give feedback.
All reactions