我有一个异步动作,这从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应该为你工作。 无论如何你都可以将你的减速器分解,就像我在指南中一样,你会知道我在说什么。 –