const [ sort, setSort ] = useState(false);
const sorted = useMemo(() => {
return [...data].sort((a, b) => {
return a.name.localeCompare(b.name) * (sort ? -1 : 1);
});
}, [ sort ]);
<button onClick={() => setSort(sort => !sort)}>Сортировать</button>