...

/

Solution Review: Reverse Sort

Solution Review: Reverse Sort

Learn to sort in a reverse order in a react app.

We'll cover the following...

Solution

The initial sort direction works for strings, as well as numeric sorts like the reverse sort for JavaScript numbers that arranges them from high to low. Now we need another state to track whether the sort is reversed or normal, to make it more complex:

Press + to interact
const List = ({ list, onRemoveItem }) => {
const [sort, setSort] = React.useState({
sortKey: 'NONE',
isReverse: false,
});
...
};

Next, give the sort handler logic to see if the incoming sortKey triggers ...