title: When to use componentWillReceiveProps lifecycle method?
body: <p>I am new to React/Redux and have a problem with state.</p>
  
  <p><strong>TrajectContainer.jsx</strong></p>
  
  <pre><code>class TrajectContainer extends React.Component {
      constructor(props) {
          super(props);
          this.state = {
              trajects: props.trajects,
              onClick: props.onClick
          };
      }
  
      componentWillReceiveProps(nextProps) {
          console.log('componentWillReceiveProps', nextProps);
          this.setState(nextProps);
      }
  
      render() {
          // When the componentWillReceiveProps is not present, the this.state will hold the old state
          console.log('rerender', this.state);
          return (&lt;div className="col-md-6"&gt;
              &lt;h2&gt;Trajects&lt;/h2&gt;
              &lt;button className="btn btn-primary" onClick={this.state.onClick}&gt;Add new Traject&lt;/button&gt;
              {this.state.trajects.map(traject =&gt; &lt;Traject traject={traject} key={traject.name}/&gt;)}
          &lt;/div&gt;)
      }
  }
  
  const mapStateToProps = function (store) {
      console.log('mapToStateProps', store);
      return {
          trajects: store.trajects
      };
  };
  
  const mapDispatchToProps = function (dispatch, ownProps) {
      return {
          onClick: function () {
              dispatch(addTraject());
          }
      }
  };
  
  export default connect(mapStateToProps, mapDispatchToProps)(TrajectContainer);
  </code></pre>
  
  <p>When a reducer returns a new state, the component will rerender with the new data.</p>
  
  <p>However: if I remove the componentWillReceiveProps function, the render() function has the old state.</p>
  
  <p>I checked the data received in mapStateToProps, and this is new New State.
  So I don't understand why I need the componentWillReceiveProps function in order for the render function to receive the new data.</p>
  
  <p>Am I doing something wrong?</p>