2023-03-07 `defaultValue` is invalid for `getFieldDecorator` will set `value`, please use `option.initialValue` instead.
`defaultValue` is invalid for `getFieldDecorator` will set `value`, please use `option.initialValue` instead.
`defaultValue`对于`getFieldDecorator`无效。如果要设置`value`,请改用`option.initialValue`。
前言:react+antd项目,使用到了form表单和一些控件。
报错原因:form表单使用了getFieldDecorator来封装控件(比如<Inputplaceholder="请输入搜索内容" />),它会自动给这个控件添加一个value,你需要给定一个默认值即initialValue,不能使用控件的defaultValue。
解决方案:
报错代码:
{getFieldDecorator('date', {
rules: [
{ required: true, message: '请输入有效日期' }
],
})(
<DatePicker
locale={date_locale}
showTime
format="YYYY年MM月DD日 HH:mm"
defaultValue={moment('2015-01-01', 'YYYY-MM-DD')}
/>
)}
正确修改为:
{getFieldDecorator('date', {
rules: [
{ required: true, message: '请输入有效日期' }
],
})(
<DatePicker
locale={date_locale}
showTime
format="YYYY年MM月DD日 HH:mm"
initialValue={moment('2015-01-01', 'YYYY-MM-DD')}
/>
)}

浙公网安备 33010602011771号