我有一個異步動作,這從REST API獲取數據陣營Redux的調度動作top = 10, skip = 0
的初始狀態。在組分:後另一個動作
class List extends Component {
componentDidMount() {
this.list();
}
nextPage() {
let top = this.props.list.top;
let skip = this.props.list.skip;
// After this
this.props.onSetSkip(skip + top);
// Here skip has previous value of 0.
this.list();
// Here skip has new value of 10.
}
list() {
this.props.List(this.props.list.top, this.props.list.skip);
}
render() {
return (
<div>
<table> ... </table>
<button onClick={this.nextPage.bind(this)}>Next</button>
</div>
);
}
}
當按鈕接着在第一次點擊時,它採用異步動作的skip
值沒有改變。 如何在同步後採取行動?
感謝您的幫助。你能提供一些示例代碼嗎? (我是一個反應敏捷的人)。 –
@DenisBednov如果你按照thunks指南,thunks應該爲你工作。 無論如何你都可以將你的減速器分解,就像我在指南中一樣,你會知道我在說什麼。 –