In AngularJS is possible sort an array like this ng-repeat="user in users | orderBy: order"
and i need to know how do this in ReactJS, here is an exemple of this in AngularJS
const myApp = angular.module('myApp', [])
myApp.controller('myAppController', ['$scope', $scope => {
$scope.users = [
{ name: 'Maria', age: 16, color: 'red' },
{ name: 'Mike', age: 18, color: 'black' },
{ name: 'John', age: 23, color: 'green' },
{ name: 'Liza', age: 21, color: 'yellow' }
]
$scope.order = 'name'
$scope.orderBy = orderBy => $scope.order = orderBy
}])
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script>
<table ng-app="myApp" ng-controller="myAppController">
<tr>
<th ng-click="orderBy('name')">Name</th>
<th ng-click="orderBy('age')">Age</th>
<th ng-click="orderBy('color')">Color</th>
</tr>
<tr ng-repeat="user in users | orderBy: order">
<td>{{user.name}}</td>
<td>{{user.age}}</td>
<td>{{user.color}}</td>
</tr>
</table>