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

fix(useWatch): default value for array of inputs #9555

Merged
merged 2 commits into from Dec 8, 2022
Merged

fix(useWatch): default value for array of inputs #9555

merged 2 commits into from Dec 8, 2022

Conversation

adesurirey
Copy link
Contributor

Closes #9530

@codesandbox
Copy link

codesandbox bot commented Dec 8, 2022

CodeSandbox logoCodeSandbox logo  Open in CodeSandbox Web Editor | VS Code | VS Code Insiders

Copy link
Member

@bluebill1049 bluebill1049 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking great! thanks a lot for the fix.

src/useWatch.ts Outdated
Comment on lines 183 to 190
const [value, updateValue] = React.useState<unknown>(
isUndefined(defaultValue)
? control._getWatch(name as InternalFieldName)
: defaultValue,
: control._getWatch(
name as InternalFieldName,
defaultValue as DeepPartialSkipArrayKey<TFieldValues>,
),
);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can simplify to the following

const [value, updateValue] = React.useState<unknown>(
  control._getWatch(
    name as InternalFieldName,
    defaultValue as DeepPartialSkipArrayKey<TFieldValues>,
  ),
);

Copy link
Member

@bluebill1049 bluebill1049 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's go! Thanks.

@bluebill1049 bluebill1049 merged commit f3f9e2d into react-hook-form:master Dec 8, 2022
@adesurirey
Copy link
Contributor Author

Thank you @bluebill1049!

@adesurirey adesurirey deleted the fix-usewatch-default-value branch December 9, 2022 07:37
@adesurirey
Copy link
Contributor Author

@bluebill1049 when will it be released?

@bluebill1049
Copy link
Member

I am planning to do the final release of the year next week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

issue: error when using useWatch with a name array and default values as object
2 participants