step 1、在父组件中:
constructor(props) {
super(props);
this.state = {
checkState:'checked',
enable:true
}
}
this.setState({
checkState:'unChecked',
enable:false
})
step 2:在调用子组件form前
<FormE ref={this.saveFormRef} checkState={this.state.checkState} enable={this.state.enable}/>
step 3:form子组件
const { form,checkState,enable} = this.props;
const { getFieldDecorator } = this.props.form;
{getFieldDecorator('status', {
rules: [{ required: false}],
valuePropName:{checkState},
initialValue:{enable}
})(
<Switch checkedChildren="启用" unCheckedChildren="禁用"/>
)}
运行报错,valuePropName:{checkState}这里应该怎样写才能动态设置呢?万分感谢!
官方文档)描写的很清楚呀: