title: React Redux: View not getting updated even though mapStateToProps is
body: <h1>My Application and Store</h1>
  
  <p>Using Redux with ReactJS, I am keeping an array of objects (called results) in the store and dispatching actions that sort and manipulate it. In mapStateToProps, I return this results array, which renders the results in a list on the view.</p>
  
  <pre><code>// in Component file
  export default class ResultList extends Component {
      constructor(props) {
          super(props);
          this.renderResults = this.renderResults.bind(this);
      }
  
      renderResults(results) {
          return (
              results.map((result) =&gt; {
                  return &lt;AnotherComponent /&gt;
              })
          );
      }
  
      render() {
          const { results } = this.props;
          return (
              &lt;div&gt;
                  &lt;ul&gt;
                      {this.renderResults(results)}
                  &lt;/ul&gt;
              &lt;/div&gt;
          )
  
  // in Container Component file
  const mapStateToProps = (state, ownProps) =&gt; {
      console.log('map state is triggered');
      return {
          results: state.results
      };
  }
  </code></pre>
  
  <h1>The Problem</h1>
  
  <p>I have found that <em>although my mapStateToProps successfully triggers to update the props to my class component,</em> for some reason <strong>the view only updates on the FIRST time that the results array gets manipulated, but does not update on future updates to the store.</strong> <em>(Please see update below. This is not entirely accurate.)</em></p>
  
  <p>I have made sure that this problem is not due to mutating state in my reducers as is often the case; I have confirmed that the mapStateToProps runs every time that the store gets updated (as indicated by the console.log). The problem seems to be between the results props getting returned from mapStateToProps and the view actually rendering the results array, but I do not have visibility to see what Redux is doing under the hood.</p>
  
  <p>The closest problem that someone else has had to what I am experiencing seems to be this, but I do not know how or if this fix applies to my use of a stored array: <a href="https://forums.meteor.com/t/the-state-is-correctly-mutated-and-returned-but-view-does-not-rerender/28840/5" rel="nofollow noreferrer">https://forums.meteor.com/t/the-state-is-correctly-mutated-and-returned-but-view-does-not-rerender/28840/5</a></p>
  
  <p>Any help would be greatly appreciated. Thank you.</p>
  
  <hr>
  
  <h1>Update</h1>
  
  <p>I apologize, but must correct my statement above saying that there are no further updates to the view after the first time the results in the store gets updated. With further testing I have found that is not completely true. <strong>The view gets updated only when the results array is sorted according to case 1 of the below sorting function. Cases 2 and 3 are the ones that result in no update to the view.</strong> This may/may not be necessary information, but the results array gets sorted by these 3 cases in a cycle onClick in the following order: case 1, case 3, case 2.</p>
  
  <pre><code>// in reducer index.js file
  case SORT_RESULTS:
      return {
          ...state,
          results: sortArr(state.results, state.sortType)
      };
  
  // sorting function
  function sortArr(arr, sortType) {
      let newArr = [];
      switch (sortType) {
          case '1':
              for (let i = arr.length - 1; i &gt;= 0; i--) {
                  newArr.push(arr[i]);
              }
              return newArr;
          case '2':
              newArr = arr;
              newArr.sort((a, b) =&gt; {
                  return b.num - a.num;
              });
              return newArr;
          case '3':
              newArr = arr;
              newArr.sort((a, b) =&gt; {
                  let id1 = a.id.toLowerCase();
                  let id2 = b.id.toLowerCase();
                  if (id1 &lt; id2) {
                      return -1;
                  }
                  if (id1 &gt; id2) {
                      return 1;
                  }
                  return 0;
              });
              return newArr;
          default:
              return arr;
      }
  }
  </code></pre>