Sorting a list in ascending/descending order with a button toggle I have this piece of code written as a function to handle a button-toggle for sorting a list in ascending and descending order. Below is the code which is working as expected, but I would appreciate if someone knows a better, shorter and cleaner way of writing it.

  // method called every time the button is clicked
  // it will change the sorting order 
  //(ASCENDING =&gt; DESCENDING =&gt; ASCENDING =&gt; DESCENDING) in that order

  onSortChange = () =&gt; {
      this.setState({
        users: this.state.order
          ? this.state.users.sort((a, b) =&gt; {
          if (a.name &lt; b.name) return -1;
          if (a.name &gt; b.name) return 1;
          return 0;
      })
          : this.state.users.reverse((a, b) =&gt; {
          if (a.name &lt; b.name) return 1;
          if (a.name &gt; b.name) return -1;
          return 0;
      }),
        order: !this.state.order,
      });
  }
```
Instead of resorting the list in state just store the preferred order in state. Then in render simply sort or reverse the order as needed to present the data. Be sure to use keys that don't change when the order is changed and it'll be quite performant.