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: useWatch<T>() (parameterless) and watch type from the useFormContext have different types #10734
Comments
Hello, EDIT: my mistake I didn't see you had to modify the form defaultValues to make the workaround to work, so it's less easy to use than I'd figured it out at the first look. RE-EDIT: there is a simplier workaround ! taking the Example 1 from the Sandbox: Replace |
Hey @SebDelile sorry for the delayed response. I didn't actually consider using That's why I went with increasing the depth of the properties instead, but it would be cool if react-hook-form could handle this without the need to modify the original data format (as you mentioned that could be uncomfortable to work with). |
…turn type (react-hook-form#11359) Co-authored-by: Beier (Bill) <bluebill1049@hotmail.com>
…eters return type (react-hook-form#11359)" This reverts commit fdbadbb.
Version Number
7.43.9
Codesandbox/Expo snack
https://codesandbox.io/s/adoring-shadow-zgr3rd?file=/src/App.tsx
Steps to reproduce
Recreated from #10721 using the template as the GitHub "new issue" from discussion functionality skips your templates.
useWatch<Form>()
anduseFormContext<Form>()
Description:
Using
useWatch<T>()
(without providing any parameters) returns a deep partial unlike the watch type fromuseFormContext
. This results in having to either cast the result to the non-partial value (T
) or @ts-ignore the type in order to get my defined type instead of the deep partial one.I can't actually just use the
useFormContext#watch
because that results in infinite updates when I try to use it the same way I useuseWatch
and gives me performance issues so I've moved away from using it even though the typing there is what I need.You can see the
Example2
file for the usage of a nested property to avoid getting deep partials.Expected behaviour
I expect that the types would be the same between the two. Unless it's some design decision for some specific case, to me it doesn't make sense for it to be a deep partial.
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: