diff --git a/src/useWatch.ts b/src/useWatch.ts index 99faf0bb..39eed878 100644 --- a/src/useWatch.ts +++ b/src/useWatch.ts @@ -76,11 +76,18 @@ function useWatch( form?: TForm | WatchOptions, ): GetGeneric; +// ------- selector type ------- function useWatch( selector: (values: GetGeneric) => TSelected, form?: TForm | WatchOptions, ): TSelected; +function useWatch( + selector: (values: ValueType) => TSelected, + form?: FormInstance | WatchOptions, +): TSelected; +// ------- selector type end ------- + function useWatch( dependencies: NamePath, form?: TForm | WatchOptions, diff --git a/tests/useWatch.test.tsx b/tests/useWatch.test.tsx index 7c97c464..843fe3a9 100644 --- a/tests/useWatch.test.tsx +++ b/tests/useWatch.test.tsx @@ -288,8 +288,29 @@ describe('useWatch', () => { const demo5 = Form.useWatch(['demo1', 'demo2', 'demo3', 'demo4', 'demo5'], form); const more = Form.useWatch(['age', 'name', 'gender'], form); const demo = Form.useWatch(['demo']); + + const values2 = Form.useWatch(values => ({ newName: values.name, newAge: values.age }), form); + const values3 = Form.useWatch(values => ({ + newName: values.name, + })); + return ( - <>{JSON.stringify({ values, main, age, demo1, demo2, demo3, demo4, demo5, more, demo })} + <> + {JSON.stringify({ + values, + main, + age, + demo1, + demo2, + demo3, + demo4, + demo5, + more, + demo, + values2, + values3, + })} + ); };