title: setState in map function of react
body: <p>My Requirement is to update the state value in map function of componentWillReceiveProps.</p>
  
  <p>In console log all I am getting is 1s but sub.subscribed contain 0s and 1s</p>
  
  <p>Reference of console window: <a href="http://prntscr.com/jqifiz" rel="nofollow noreferrer">http://prntscr.com/jqifiz</a></p>
  
  <pre><code>constructor(props) {
      super(props);
        this.state = {
          regionAll: [],
        };
      }
  componentWillReceiveProps(nextProps){
      if(nextProps.apiData !== false ){
        nextProps.apiData.data.datacenter.category.map((sub)=&gt; {
          console.log(sub.subscribed,'sub.subscribed');
          this.setState({
            regionAll: [
              ...this.state.regionAll,
              sub.subscribed
            ]
          },()=&gt;{
            console.log(this.state.regionAll,'sub');
          })
        })
    }
  </code></pre>
  
  <p>Is this a correct way to update state in reactjs?</p>