mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-24 02:59:58 +08:00
feat: support selector (#46180)
* feat: support selector * fix: ts text * feat: md * feat: snap
This commit is contained in:
parent
e6bf2e24a6
commit
f5e0408649
@ -19514,6 +19514,9 @@ Array [
|
||||
<pre>
|
||||
Name Value:
|
||||
</pre>
|
||||
<pre>
|
||||
Custom Value: name:
|
||||
</pre>
|
||||
</article>,
|
||||
]
|
||||
`;
|
||||
|
@ -8256,6 +8256,9 @@ Array [
|
||||
<pre>
|
||||
Name Value:
|
||||
</pre>
|
||||
<pre>
|
||||
Custom Value:
|
||||
</pre>
|
||||
</article>,
|
||||
]
|
||||
`;
|
||||
|
@ -4,6 +4,8 @@ import { Form, Input, InputNumber, Typography } from 'antd';
|
||||
const Demo: React.FC = () => {
|
||||
const [form] = Form.useForm<{ name: string; age: number }>();
|
||||
const nameValue = Form.useWatch('name', form);
|
||||
// The selector is static and does not support closures.
|
||||
const customValue = Form.useWatch((values) => `name: ${values.name || ''}`, form);
|
||||
|
||||
return (
|
||||
<>
|
||||
@ -18,6 +20,7 @@ const Demo: React.FC = () => {
|
||||
|
||||
<Typography>
|
||||
<pre>Name Value: {nameValue}</pre>
|
||||
<pre>Custom Value: {customValue}</pre>
|
||||
</Typography>
|
||||
</>
|
||||
);
|
||||
|
@ -387,7 +387,9 @@ export default () => {
|
||||
|
||||
### Form.useWatch
|
||||
|
||||
`type Form.useWatch = (namePath: NamePath, formInstance?: FormInstance | WatchOptions): Value`
|
||||
`type Form.useWatch = (namePath: NamePath | (selector: (values: Store) => any), formInstance?: FormInstance | WatchOptions): Value`
|
||||
|
||||
`5.12.0` add `selector`
|
||||
|
||||
Watch the value of a field. You can use this to interact with other hooks like `useSWR` to reduce development costs:
|
||||
|
||||
|
@ -386,7 +386,9 @@ export default () => {
|
||||
|
||||
### Form.useWatch
|
||||
|
||||
`type Form.useWatch = (namePath: NamePath, formInstance?: FormInstance | WatchOptions): Value`
|
||||
`type Form.useWatch = (namePath: NamePath | (selector: (values: Store)) => any, formInstance?: FormInstance | WatchOptions): Value`
|
||||
|
||||
`5.12.0` 新增 `selector`
|
||||
|
||||
用于直接获取 form 中字段对应的值。通过该 Hooks 可以与诸如 `useSWR` 进行联动从而降低维护成本:
|
||||
|
||||
|
@ -132,7 +132,7 @@
|
||||
"rc-dialog": "~9.3.4",
|
||||
"rc-drawer": "~6.5.2",
|
||||
"rc-dropdown": "~4.1.0",
|
||||
"rc-field-form": "~1.40.0",
|
||||
"rc-field-form": "~1.41.0",
|
||||
"rc-image": "~7.5.1",
|
||||
"rc-input": "~1.3.6",
|
||||
"rc-input-number": "~8.4.0",
|
||||
|
Loading…
Reference in New Issue
Block a user