-
-
Notifications
You must be signed in to change notification settings - Fork 272
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
feat: useWatch support selector #637
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #637 +/- ##
=======================================
Coverage 99.43% 99.43%
=======================================
Files 18 18
Lines 1236 1240 +4
Branches 283 285 +2
=======================================
+ Hits 1229 1233 +4
Misses 7 7 ☔ View full report in Codecov by Sentry. |
src/useWatch.ts
Outdated
@@ -126,7 +133,11 @@ function useWatch(...args: [NamePath, FormInstance | WatchOptions<FormInstance>] | |||
const { registerWatch } = getInternalHooks(HOOK_MARK); | |||
|
|||
const cancelRegister = registerWatch((values, allValues) => { | |||
const newValue = getValue(options.preserve ? allValues : values, namePathRef.current); | |||
const _values = options.preserve ? allValues : values; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不要用下划线命名,rawValues
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
提出来了
src/useWatch.ts
Outdated
options.preserve ? getFieldsValue(true) : getFieldsValue(), | ||
namePathRef.current, | ||
); | ||
const initialValue = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个和上面的逻辑很相似,看看能不能抽出来
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
就等着呢
@@ -76,6 +76,11 @@ function useWatch<TForm extends FormInstance>( | |||
form?: TForm | WatchOptions<TForm>, | |||
): GetGeneric<TForm>; | |||
|
|||
function useWatch<TForm extends FormInstance, TSelected = unknown>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
因为用了 TSelected,所以不建议 const values = useWatch<{name?: string}>(values => xxx)
设置 stroe 类型方式
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不过还是支持了
…into support-selector
src/useWatch.ts
Outdated
@@ -125,8 +139,15 @@ function useWatch(...args: [NamePath, FormInstance | WatchOptions<FormInstance>] | |||
const { getFieldsValue, getInternalHooks } = formInstance; | |||
const { registerWatch } = getInternalHooks(HOOK_MARK); | |||
|
|||
const getNewValue = (values: any, allValues: any) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-> getWatchValue
options.preserve ? getFieldsValue(true) : getFieldsValue(), | ||
namePathRef.current, | ||
); | ||
const initialValue = getWatchValue(getFieldsValue(), getFieldsValue(true)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
还记得 Form.List 下需要设置 getFieldsValue({ strict: true })
吗,这个true
跟strict
不能同时设置,需要加个options.strict
吗
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
暂时不用,有需求再加
RFC: ant-design/ant-design#46173