New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
issue: Incorrect getValues()
after reset when isValid
is destructured from formState
#11368
Comments
|
I don't really want to subscribe to the updates, though, I just want to have access to the latest values when render does happen to be called. |
And render is being called in this case, but |
I just checked, and |
I understand this may be tedious, but could you please review this codesandbox to identify any differences in core logic between my implementation and yours? This will help us determine the cause of the issue you are experiencing. Currently, my codesandbox is functioning as expected: the values displayed in the |
Thanks so much for taking a look, @Moshyfawn. I've forked your sandbox to show the issue: https://codesandbox.io/p/devbox/admiring-jasper-8fctzf The difference is that I am using |
@IanVS i couldn't reproduce the issue (with your steps), could you share a video? |
The codesandbox that Ian linked to is my codesandbox that I've shared with them. I've modified it again to suit Ian's use-case; you can now reproduce the problem. Here's the screencast too. Note that after the form is reset, there is a re-render that forces the values to be logged, but they don't update to the values in the form. The above I've tracked it down to how the csb-rhf-dirty.mp4 |
you can resolve this issue with the following, it does make things complicated when you try to provide reset values and then keep what on the screen. reset(
undefined,
{ keepDirty: true, keepDirtyValues: true },
) I will add a note in the doc.
|
Thanks, but I do want to update the default values in my situation (and any non-dirty form values). Are you saying that this is working as intended? |
@IanVS is rather a difficult case when isValid is |
…es (react-hook-form#11384) * fix react-hook-form#11368 keep form state mounted when keeping values * fix logic condition * update unit tests * remove only * improve unit test
Version Number
7.49.2
Codesandbox/Expo snack
https://codesandbox.io/p/sandbox/funny-kapitsa-j7vqmk
Steps to reproduce
getValues()
is different from what is rendered.Expected behaviour
I was confused why
getValues()
was returning something different from what the form was actually rendering, and narrowed it down to only happening whenisValid
is destructured from formState. I need to usereset
withkeepDirtyValues
, and it almost works, except for resetting the value returned bygetValues()
What browsers are you seeing the problem on?
No response
Relevant log output
No response
Code of Conduct
The text was updated successfully, but these errors were encountered: