不生效的写法:
const theQuery = Object.assign( {}, {
id: '',
beginDate: '',
endDate: '' // 查询条件
}, _query.toJS() );
this.setState(theQuery);
action.getRefundList(theQuery)
可以生效的写法1:
const theQuery = Object.assign( {}, {
id: '',
beginDate: '',
endDate: '' // 查询条件
}, _query.toJS() );
this.setState(theQuery, () => {
action.getRefundList(theQuery)
} );
可以生效的写法2:
const theQuery = Object.assign( {}, {
id: '',
beginDate: '',
endDate: '' // 查询条件
}, _query.toJS() );
this.setState(Object.assign( {}, theQuery );
action.getRefundList(theQuery)
具体原因我却不太清楚,还望路过的大神们不吝赐教~
本文探讨了在使用React时遇到的setState操作与函数调用不同步的问题,对比了两种写法,一种未能立即触发更新,另一种则能正确实现状态更新后的回调调用。
1万+

被折叠的 条评论
为什么被折叠?



