Skip to content

feat: useWatch support selector - #637

Merged
zombieJ merged 8 commits into
react-component:masterfrom
crazyair:support-selector
Nov 30, 2023
Merged

feat: useWatch support selector#637
zombieJ merged 8 commits into
react-component:masterfrom
crazyair:support-selector

Conversation

@crazyair

@crazyair crazyair commented Nov 29, 2023

Copy link
Copy Markdown
Contributor

@vercel

vercel Bot commented Nov 29, 2023

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
field-form ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 30, 2023 2:41am

@codecov

codecov Bot commented Nov 29, 2023

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (75dbcb3) 99.43% compared to head (3891f26) 99.43%.

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.
📢 Have feedback on the report? Share it here.

Comment thread src/useWatch.ts Outdated

const cancelRegister = registerWatch((values, allValues) => {
const newValue = getValue(options.preserve ? allValues : values, namePathRef.current);
const _values = options.preserve ? allValues : values;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不要用下划线命名,rawValues

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

提出来了

Comment thread src/useWatch.ts Outdated
options.preserve ? getFieldsValue(true) : getFieldsValue(),
namePathRef.current,
);
const initialValue =

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个和上面的逻辑很相似,看看能不能抽出来

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

就等着呢

Comment thread src/useWatch.ts
form?: TForm | WatchOptions<TForm>,
): GetGeneric<TForm>;

function useWatch<TForm extends FormInstance, TSelected = unknown>(

Copy link
Copy Markdown
Contributor Author

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 类型方式

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不过还是支持了

Comment thread src/useWatch.ts Outdated
const { getFieldsValue, getInternalHooks } = formInstance;
const { registerWatch } = getInternalHooks(HOOK_MARK);

const getNewValue = (values: any, allValues: any) => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-> getWatchValue

Comment thread src/useWatch.ts
options.preserve ? getFieldsValue(true) : getFieldsValue(),
namePathRef.current,
);
const initialValue = getWatchValue(getFieldsValue(), getFieldsValue(true));

Copy link
Copy Markdown
Contributor Author

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 }) 吗,这个truestrict不能同时设置,需要加个options.strict

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

暂时不用,有需求再加

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants