Skip to content

Instantly share code, notes, and snippets.

@Ateevduggal
Created June 11, 2022 05:15
const Sort = (sort) => {
if (order === "asc") {
const sorted = [...tableData.sort((a, b) => (a[sort] > b[sort] ? 1 : -1))];
console.log(sorted);
setTableData(sorted);
setOrder("desc"); // descending order - desc
} else if (order === "desc") {
const sorted = [...tableData.sort((a, b) => (a[sort] < b[sort] ? 1 : -1))];
console.log(sorted);
setTableData(sorted);
setOrder("asc");
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment