[antd: Switch] `value` is not validate prop, do you mean `checked`

在Form中使用Switch时出现这个错误。

原先的写法:

  <Form.Item label="启用">
            {getFieldDecorator('active', {
              initialValue: _.get(data, 'active', true),
            })(
              <Switch defaultChecked={_.get(data, 'active', true)} />
            )}
          </Form.Item>

 

问题在defaultChecked上,在form中的getFieldDecorator中需要通过checked来确认值,解决方法,添加valuePropName:

 <Form.Item label="启用">
            {getFieldDecorator('active', {
              initialValue: _.get(data, 'active', false),
              valuePropName: 'checked'
            })(
              <Switch />
            )}
          </Form.Item>

 

相关文章:

  • 2022-12-23
  • 2021-11-26
  • 2022-12-23
  • 2021-12-10
  • 2022-12-23
  • 2021-09-02
  • 2022-02-15
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-05
  • 2021-11-09
  • 2022-12-23
相关资源
相似解决方案