From 4902c5a4f098557153d3b4c982c367ee7d169abe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=81=8F=E5=8F=B3?= Date: Tue, 21 Apr 2020 16:42:56 +0800 Subject: [PATCH] =?UTF-8?q?docs:=20=F0=9F=93=96=20update=20Form=20ts=20dem?= =?UTF-8?q?o=20for=20createRef=20(#23440)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit close #23417 --- components/form/demo/control-ref.md | 3 ++- components/form/index.en-US.md | 2 +- components/form/index.zh-CN.md | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/components/form/demo/control-ref.md b/components/form/demo/control-ref.md index e1763ec2bb..981bc57931 100644 --- a/components/form/demo/control-ref.md +++ b/components/form/demo/control-ref.md @@ -15,6 +15,7 @@ We recommend use `Form.useForm` to create data control. If you are using class c ```tsx import { Form, Input, Button, Select } from 'antd'; +import { FormInstance } from 'antd/lib/form'; const { Option } = Select; @@ -27,7 +28,7 @@ const tailLayout = { }; class Demo extends React.Component { - formRef = React.createRef(); + formRef = React.createRef(); onGenderChange = value => { this.formRef.current.setFieldsValue({ diff --git a/components/form/index.en-US.md b/components/form/index.en-US.md index 084ae1aeea..37a765ad3b 100644 --- a/components/form/index.en-US.md +++ b/components/form/index.en-US.md @@ -312,7 +312,7 @@ Before Modal open, children elements do not exist in the view. You can set `forc Components inside Form.Item with name property will turn into controlled mode, that makes `defaultValue` does not work anymore. Please try `initialValues` of Form to set default value. -### Why resetFields will re-mount component? +### Why `resetFields` will re-mount component? `resetFields` will re-mount component under Field to clean up customize component side effect(like asyn data, cached state, etc.). It's by design. diff --git a/components/form/index.zh-CN.md b/components/form/index.zh-CN.md index 1b6ab3dfe3..574aac58bf 100644 --- a/components/form/index.zh-CN.md +++ b/components/form/index.zh-CN.md @@ -309,11 +309,11 @@ validator(rule, value, callback) => { 这是因为你在调用 form 方法时,Modal 还未初始化导致 form 没有关联任何 Form 组件。你可以通过给 Modal 设置 `forceRender` 将其预渲染。示例点击[此处](https://codesandbox.io/s/antd-reproduction-template-ibu5c)。 -### 为什么 Form.Item 下的子组件 defaultValue 不生效? +### 为什么 Form.Item 下的子组件 `defaultValue` 不生效? 当你为 Form.Item 设置 `name` 属性后,子组件会转为受控模式。因而 `defaultValue` 不会生效。你需要在 Form 上通过 `initialValues` 设置默认值。 -### 为什么 resetFields 会重新 mount 组件? +### 为什么 `resetFields` 会重新 mount 组件? `resetFields` 会重置整个 Field,因而其子组件也会重新 mount 从而消除自定义组件可能存在的副作用(例如异步数据、状态等等)。