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 从而消除自定义组件可能存在的副作用(例如异步数据、状态等等)。