无法更新状态获取错误-超过最大更新深度

时间:2019-09-05 12:24:22

标签: react-redux

我正在尝试更新会话列表,但在调用this.props.updatedSessions()时遇到了提到的错误

我打电话给动作创建者updateSessions做同样的事情。

您可以在上查看完整的代码 https://github.com/aroraankitesh/ntlf/tree/filterTest

renderSession() {
let updatedSessionsKey = [];
return this.props.sessions.map((session, index, sessions) => {      
  if (
    this.calculateDay(session.event_start_day) === this.props.day &&
    this.props.selectedVenue === "all" &&
    this.props.selectedType === "all"
  ) {
    return <li key={session.event_key}>{session.name}</li>;
  }


  if (
    this.calculateDay(session.event_start_day) === this.props.day &&
    session.venue === this.props.selectedVenue &&
    this.props.selectedType === "all"
  ) {
    updatedSessionsKey.push(session.event_key);
    // update sessions
    if(sessions.length - 1 === index){
      console.log(1);
      this.props.updateSessions(updatedSessionsKey);
    }
    return <li key={session.event_key}>{session.name}</li>;
  }

  if (
    this.calculateDay(session.event_start_day) === this.props.day &&
    this.props.selectedVenue === "all" &&
    session.event_type === this.props.types[this.props.selectedType].name
  ) {
    updatedSessionsKey.push(session.event_key);
    // update sessions
    if(sessions.length - 1 === index){
      console.log(index);
      console.log(1);
      this.props.updateSessions(updatedSessionsKey);
    }

    return <li key={session.event_key}>{session.name}</li>;
  }


  if(sessions.length - 1 === index){
    console.log(1);
    this.props.updateSessions(updatedSessionsKey);
  }



  return null;
});

}

0 个答案:

没有答案