-
-
Notifications
You must be signed in to change notification settings - Fork 272
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: useWatch support selector (#637)
* feat: api * feat: test * feat: 代码优化 * feat: 添加显示声明类型支持 * feat: 下划线优化 * feat: 下划线优化 * feat: watchValue
- Loading branch information
Showing
4 changed files
with
112 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
## useWatch-selector | ||
|
||
<code src="../examples/useWatch-selector.tsx"></code> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import React from 'react'; | ||
import Form, { Field } from 'rc-field-form'; | ||
import Input from './components/Input'; | ||
|
||
type FieldType = { | ||
init?: string; | ||
name?: string; | ||
age?: number; | ||
}; | ||
|
||
export default () => { | ||
const [form] = Form.useForm<FieldType>(); | ||
const values = Form.useWatch( | ||
values => ({ init: values.init, newName: values.name, newAge: values.age }), | ||
{ form, preserve: true }, | ||
); | ||
console.log('values', values); | ||
return ( | ||
<> | ||
<Form form={form} initialValues={{ init: 'init', name: 'aaa' }}> | ||
name | ||
<Field name="name"> | ||
<Input /> | ||
</Field> | ||
age | ||
<Field name="age"> | ||
<Input /> | ||
</Field> | ||
no-watch | ||
<Field name="no-watch"> | ||
<Input /> | ||
</Field> | ||
values:{JSON.stringify(values)} | ||
</Form> | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8bbfd34
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.
Successfully deployed to the following URLs:
field-form – ./
field-form-git-master-react-component.vercel.app
field-form.vercel.app
field-form-react-component.vercel.app