From 4800c589da7ab4ffaa602400b6e93855cac0aca4 Mon Sep 17 00:00:00 2001 From: crazyair <645381995@qq.com> Date: Thu, 30 Nov 2023 10:00:42 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E5=A3=B0=E6=98=8E=E7=B1=BB=E5=9E=8B=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/useWatch.ts | 7 +++++++ tests/useWatch.test.tsx | 23 ++++++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) 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, + })} + ); };