问题:提交表单成功后,输入框重置失败,打印出来发现postDraft(表单草稿)还是有值的;
Reducer.js
case meetingAction.CLEAR_MEETING_UNIT:
//KEY1:清除postDraft
return Object.assign({},state,{postDraft:{}});
case meetingAction.CLEAR_MEETING_ALL:
return Object.assign({},initState);
Action.js
export function clearMeeting() {
return {
type: meetingAction.CLEAR_MEETING_UNIT
}
}
export function submitMeeting(meetingInfo){
return function(dispatch,getState){
if( shouldPost(getState().meeting ) ){
return console.log('已经在申请会议中')
}
dispatch(startPost());
return new Promise(function(rev,rej){
setTimeout(function(){
rev()
},1500)
}).then(function(){
dispatch( endPost() );
dispatch( addMeeting(meetingInfo) );
//KEY2: 模拟成功时,清空表单草稿postDraft
dispatch( clearMeeting() )
},function(){
dispatch( endPost() );
})
}
}
Page container.js
componentDidMount() {
let { postInfo: { postDraft} } = this.props;
//KEY3: 切换页面回来仍旧还是原来输入框的值
console.log('再次进入',postDraft)
this.setState( postDraft )
}
请问码由问题出在哪个环节了?
顺便,在提交表单成功后,怎么样跳转到其他页面:
1.是写在submitMeeting回调中,写hashHistory.push('/someplace');
2.还是单独维护一个瞬间属性到store,然后在componentWillReceiveProps一旦检测到就hashHistory.push('/someplace'),再重置该瞬间属性;