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

🕯️ close #9524 useWatch return undefined value #9653

Merged
merged 1 commit into from Dec 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/logic/generateWatchOutput.ts
Expand Up @@ -7,7 +7,7 @@ export default <T>(
_names: Names,
formValues?: FieldValues,
isGlobal?: boolean,
defaultValue?: DeepPartial<T>,
defaultValue?: DeepPartial<T> | unknown,
) => {
if (isString(names)) {
isGlobal && _names.watch.add(names);
Expand Down
17 changes: 9 additions & 8 deletions src/useWatch.ts
Expand Up @@ -3,7 +3,6 @@ import React from 'react';
import generateWatchOutput from './logic/generateWatchOutput';
import shouldSubscribeByName from './logic/shouldSubscribeByName';
import cloneObject from './utils/cloneObject';
import isUndefined from './utils/isUndefined';
import {
Control,
DeepPartialSkipArrayKey,
Expand Down Expand Up @@ -167,14 +166,16 @@ export function useWatch<TFieldValues extends FieldValues>(
exact,
)
) {
const fieldValues = generateWatchOutput(
_name.current as InternalFieldName | InternalFieldName[],
control._names,
formState.values || control._formValues,
);

updateValue(
isUndefined(fieldValues) ? defaultValue : cloneObject(fieldValues),
cloneObject(
generateWatchOutput(
_name.current as InternalFieldName | InternalFieldName[],
control._names,
formState.values || control._formValues,
false,
defaultValue,
),
),
);
}
},
Expand Down