Replies: 2 comments
-
Hmm. My "hack" isn't reliable. I must have missed something essential. Please help me understand. Here is what I want to achieve:
The
The same concept is used for I'm rendering {isDirty, etc} from useFormState() under my form, so I can see that isDirty changes to true as soon as I click a checkbox. My
My call to submitForm seems to happen before onChange(e) has had the chance to update isDirty. I'm guessing that I have messed up something. I thought it would siffice to I cannot get a "fresh" isDirty within the submitForm function since hooks cannot be used there. I'm now contemplating to create a special Submit-component so I can get fresh isDirty values from the useFormState hook, but I don't think this should be this complicated. Where am I going wrong? ---- edit:
|
Beta Was this translation helpful? Give feedback.
-
I now have a working solution, but I'd love to hear if I could have solved this better? If
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I have a
submitForm()
function which is given to my components via context. I.e. I can explicitly call submitForm from any of my form components.The submitForm function calls RHF's
handleSubmit
and alsoonSubmit
if provided as a prop.I only want to call
handleSubmit
if the form isDirty, so I check this from within thesubmitForm
function. This value is read fromuseFormState
in the same component assubmitForm
is declared.Problem:
isDirty
is not always "up to date". My current solution is to wrap the call in asetTimeout(.., 0)
to wait a tick. But this is a hacky solution. I'm wondering what the correct solution would be?Beta Was this translation helpful? Give feedback.
All reactions