反应不呈现状态变化

React not rendering on state change

代码如下:

class Twitch extends React.Component {
  constructor(props){
    super(props);
    this.state={
      channelList:null,
      streamError:false,
      channelError:false,

    }
    self=this;
    this.getChannels = this.getChannels.bind(this);
  }

  componentWillMount() {
    this.getChannels();
  }

  shouldComponentUpdate(nextProps, nextState) {
    if (this.props.color !== nextProps.color) {
      return true;
    }
    if (this.state.channelList !== nextState.channelList) {
      return true;
    }
    return false;
  }

  getChannels(){
    let channels=["ESL_SC2", "OgamingSC2", 
                  "cretetion", "freecodecamp", 
                  "storbeck", "habathcx", 
                  "RobotCaleb", "noobs2ninjas", 
                  "brunofin", "comster404"
                 ];

    let resultSet=[];
    channels.map(function(channel){
      axios.get('https://wind-bow.gomix.me/twitch-api/streams/'+channel)
      .then(function (response) {
         let resObj={};
         resObj=response.data;
         axios.get('https://wind-bow.gomix.me/twitch-api/channels/'+channel)
         .then(function (response) {
            resObj.channel=response.data;
            resultSet.push(resObj);

         })
         .catch(function (error) {
            console.log("channel error",error.response);
            this.setState({channelError:true});
         });

      })
      .catch(function (error) {
            console.log("stream error",error.response);
            this.setState({streamError:true});
      });
    })
    this.setState({channelList:resultSet});
  }

  render(){
    console.log('this.state',this.state);// ---------a
    const {channelList} =this.state;
    return(
      <div className="container"> 

        {channelList.length>0 &&
          <div>
           //render stuff here 

         </div>         
        }
      </div>
    );
  }
}


ReactDOM.render(
  <Twitch />,
  document.getElementById('app')
);

API 调用工作正常,我正在向状态获取数据。然而,重新渲染并没有发生。 console.log(a) returns 数组长度首先为 0,扩展时长度适当。

我解决了。 结果 shouldComponentUpdate 返回了 false 并且没有让重新渲染发生。 我删除了那个方法。现在工作正常