来自componentWillMount的Redux路由器无限循环

时间:2017-01-20 06:03:43

标签: reactjs redux

我有以下代码

componentWillMount(){
    this.props.getCourse(null, this.props.location.query.course_id);
  }

  componentWillReceiveProps(nextProps) {
    var currCourse_id = this.props.course_details.course_id;
    var nextCourse_id = this.props.location.query.course_id;
    if (nextCourse_id !== currCourse_id) {
      this.props.getCourse(null, nextCourse_id);
    }
  }

我在CWRP函数中尝试了各种组合,但我最终得到了一个无限循环。但是,屏幕会更改为新课程。有关在currCourse_idnextCourse_id中添加内容的任何建议都会有所帮助。我尝试调度getCourse操作(这是一个API端点)并使用新道具更新组件。

1 个答案:

答案 0 :(得分:0)

尝试更改此行 -

var nextCourse_id = nextProps.location.query.course_id;
相关问题