React setState没有及时更新
1.封装 setFieldsValue 方法
/**
* 更新state中的值
* data:{stateFieldName1:stateFieldvalue1...}
*/
setStateFieldsValues = data => {
const {
form: { setFieldsValue },
} = this.props
for (var fieldName in data) {
this.setState({ [fieldName]: data[fieldName] })
setFieldsValue({ [fieldName]: data[fieldName] })
}
}
2.调用
setStateFieldsValues({
"field1": "1",
"field2": "2",
"field3": "3",
})