question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

reset method doesn't update the subscriber of useWatch if defaultValue is provided

See original GitHub issue

Describe the bug reset method doesn’t update the watched field (by useWatch) if a defaultValue is provided in the useWatch.

To Reproduce Steps to reproduce the behavior: (please use the codesandbox below)

  1. refresh the page
  2. wait for 3s for the reset method to get called
  3. the subscriber to test field is updated with the new value
  4. if adding a default value to useWatch, the subscriber doesn’t get updated with the new value after calling reset

Codesandbox link https://codesandbox.io/s/funny-kalam-gf05v?file=/src/App.js

Expected behavior I am not sure if this is a bug or an intended behavoir. However, I think in all cases calling reset method should update the subscribers of useWatch

Desktop (please complete the following information):

  • OS: macOs
  • Browser firefox
  • Version 80.0

Thank you for your hard work!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
ahmdhatcommented, Aug 31, 2020

It is clear now. Thank you for you time 😃

1reaction
bluebill1049commented, Aug 31, 2020

That’s what I meant above, reset API will reset the defaultValues, but with useWatch inline defaultValue will take over that value.

Read more comments on GitHub >

github_iconTop Results From Across the Web

useWatch | React Hook Form - Simple React forms validation
Note: the first render will always return defaultValue when it's supplied. ... which means if you update a form value before the subscription...
Read more >
why isn't the useWatch defaultValue not being overwritten?
I have the following code in one file and I am watching 2 fields to see if 1 or both are undefined and...
Read more >
React Hook Form - Reset form with default values and clear ...
The solution is to use the reset() function from the React Hook Form library, if you execute the function without any parameters (...
Read more >
React-Hook-Form Library | Common Use Cases
When the value gets provided, after clicking on the reset button, not only the value in the UI will be updated, but also...
Read more >
React Hook Form - useForm: watch - YouTube
This session cover register API inside react hook form.Doc: https://react-hook-form.com/api/useform/watch.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found