【发布时间】:2017-11-02 09:38:27
【问题描述】:
我对 React 应用程序中生命周期阶段的顺序感到困惑。我有以下课程:
constructor(props) {
super(props);
this.state = {
skip: 0
}
}
fetchMoreArticles() {
this.props.dispatch(fetchArticles(this.state.skip))
this.setState({skip: (this.state.skip + 5)})
console.log(this.state.skip); //This outputs 0 on page refresh???
}
componentDidMount() {
this.fetchMoreArticles()
}
当我写入控制台时(请参阅fetchMoreArticles()),我希望输出为 5,但它是 0。有人可以解释原因吗?
注意:fetchArticles() 是一个使用 Redux 的 ajax 调用
【问题讨论】: