Skip to content

Commit

Permalink
🕯️ close #9524 useWatch return undefined value
Browse files Browse the repository at this point in the history
  • Loading branch information
bluebill1049 committed Dec 23, 2022
1 parent eb30119 commit c8475ce
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
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

0 comments on commit c8475ce

Please sign in to comment.