我有一个表单,其中有一个名为statusMessage的道具(存储在我的商店中)。每当用户单击“提交”表示成功或“失败”时,将设置该值。如果为“成功”,则表单应清除onSubmit。即使我的statusMessage出现在我的应用中,我的onSubmit函数也不会使用statusMessage数据刷新。
onSubmit = values => {
if (this.disabledButtonCheck() && !this.msrConflictCheck(this.props.agentTableData)) {
if (values.type === 'F') {
const {id: templateId} = this.props.templateTableData[0];
let UTCDate = moment(values.futureDate)
._d.toISOString()
.split('.')[0];
const {description: changeDescription, requestor_id: requestorId, type: changeType} = values;
const agents = this.props.agentTableData.map(row => row.loginName);
const futureChangesJSON = {
changeType,
templateId,
requestedStartTimestamp: UTCDate,
changeDescription,
requestorId,
lastUpdatedBy: this.props.userRoles,
agents
};
this.props.submitFutureChanges(futureChangesJSON);
} else {
let agentsJSON = agentPOSTDataFilter(this.props.agentTableData);
let selectedTemplateID = templatePOSTDataFilter(this.props.templateTableData);
this.props.submitTemplateAssignment(agentsJSON, selectedTemplateID);
}
}
console.log("this.props.statusMessage: ", this.props.statusMessage) // prints {userMessage: "", messageType: "", callsWithError: {…}}
window.scrollTo(0, 0);
};
但是在我的渲染函数中:this.props.userMessage用正确的消息更新。我不知道为什么。 {userMessage:“”,messageType:“”,callsWithError:{…}}
const SearchPageForm = reduxForm({ 形式:“ searchPage”, destroyOnUnmount:是, initialValues:{type:'P'} })(SearchPage);
/* istanbul ignore next*/
const mapStateToProps = state => {
let searchPageFormData = getFormValues('searchPage')(state);
let newtemplateTableData = [...state.templateTableData];
let templateFormSubmission = isValid('searchPage')(state);
if (newtemplateTableData.length) {
const getDepartmentNamesFromSelector = getDepartmentNames();
const getCosaNameFromSelector = getCosaName();
const getSupplierNamesFromSelector = getSupplierNames();
newtemplateTableData[0].supplierNames = getSupplierNamesFromSelector(state);
newtemplateTableData[0].departmentNames = getDepartmentNamesFromSelector(state);
newtemplateTableData[0].cosaName = getCosaNameFromSelector(state);
}
return {
addNewTemplate: state.addNewTemplate,
agentData: state.agentData,
agentTableData: state.agentTableData,
bulkUpload: state.bulkUpload,
searchPageFormData,
statusMessage: state.statusMessage,
submitStatusCode: state.submitStatusCode,
templateData: state.templateData,
templateFormSubmission,
templateIdData: state.templateIdData,
templateTableData: newtemplateTableData,
userRoles: state.userRoles.eagleId
};
};
export default withRouter(
connect(mapStateToProps, {
addAgentIdAsInvalid,
addNewTemplate,
clearMessage,
duplicateAgent,
duplicateTemplate,
getDepartmentData,
getTemplateData,
getTemplateDataByID,
getAgentDetail,
reset,
resetAgentTable,
resetTemplateById,
removeTemplate,
restoreBulkAgents,
showModal,
setTemplateData,
setAgentData,
submitTemplateAssignment,
submitFutureChanges,
uploadAgent
})(SearchPageForm)
);