mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-02 15:59:38 +08:00
beeaf2d221
* docs: more about useWatch * test: Update test case * docs: more info * docs: more & more * feat: add useFormInstance * chore: add version info
1.0 KiB
1.0 KiB
order | version | title | ||||
---|---|---|---|---|---|---|
3.3 | 4.20.0 |
|
zh-CN
useWatch
允许你监听字段变化,同时仅当改字段变化时重新渲染。API 文档请查阅此处。
en-US
useWatch
helps watch the field change and only re-render for the value change. API Ref.
import React from 'react';
import { Form, Input, InputNumber, Typography } from 'antd';
const Demo = () => {
const [form] = Form.useForm<{ user: { name: string; age: number } }>();
const nameValue = Form.useWatch('name', form);
return (
<>
<Form form={form} layout="vertical" autoComplete="off">
<Form.Item name="name" label="Name (Watch to trigger rerender)">
<Input />
</Form.Item>
<Form.Item name="age" label="Age (Not Watch)">
<InputNumber />
</Form.Item>
</Form>
<Typography>
<pre>Name Value: {nameValue}</pre>
</Typography>
</>
);
};
export default Demo;