Skip to content
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

Stale useWatch value #2738

Closed
imcyee opened this issue Aug 27, 2020 · 6 comments
Closed

Stale useWatch value #2738

imcyee opened this issue Aug 27, 2020 · 6 comments
Labels
question Further information is requested

Comments

@imcyee
Copy link

imcyee commented Aug 27, 2020

Describe the bug
useWatch returning stale value(default value) instead of latest value (Latest version of react-hook-form)

To Reproduce
Steps to reproduce the behavior:

  1. Go to the sandbox
  2. Edit the name or age
  3. click Turn on watch display
  4. See value is not updated

Codesandbox link (Required)
https://codesandbox.io/s/react-hook-form-wizard-form-forked-f4wmt?file=/src/index.js

Expected behavior
The value should have updated, but this on works if watch display is on all the time.

@bluebill1049 bluebill1049 added the status: under investigation aware of this issue and pending for investigation label Aug 27, 2020
@bluebill1049
Copy link
Member

bluebill1049 commented Aug 27, 2020

Thanks for the issue report, look like this is expected behavior rather than a bug. as for now, we are getting defaultValue of useWatch from defaultValue at useWatch or defaultValues from useForm.

https://github.com/react-hook-form/react-hook-form/blob/master/src/useWatch.ts#L62

If this is your requirement, I would recommend to have useWatch on and remove the toggle.

feel free to submit a feature request regarding this problem, I will tag with for waiting for upvotes, then work on depending on the demand from the community.

@bluebill1049 bluebill1049 added question Further information is requested and removed status: under investigation aware of this issue and pending for investigation labels Aug 27, 2020
@imcyee
Copy link
Author

imcyee commented Aug 27, 2020

Alright then, I will go with a feature request. Thanks!

@imcyee imcyee closed this as completed Aug 27, 2020
@bluebill1049
Copy link
Member

Thanks @cYee992 👍

@imcyee
Copy link
Author

imcyee commented Aug 27, 2020

@bluebill1049 I have given it some thought about it. I am not so sure am I using useWatch right. Let's say the user key in a form with quatity and price, they can click on the button to show a 'total price' modal, before submit. without the latest value it will be the generated based on initial default values which is always wrong. Or am I using it wrong? is that it should be the usecase of watch() since it will unmount eventually?

@bluebill1049
Copy link
Member

@cYee992 if you keep useWatch running, without toggle it on and off. I think it should work for you. Do you have a simple codesandbox to mimic your app behavior? I can take a look at it tmr (it's late here).

@imcyee
Copy link
Author

imcyee commented Aug 27, 2020

Alright~ For sure! Thanks for the swift reply!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 14, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants