obsidian-test-vault/ui/utils.jsx

15 lines
415 B
JavaScript

return {
useSortedQuery(query, sortField, debounce = 1) {
const q = dc.useQuery(query, {debounce});
const b = dc.useIndexUpdates({debounce})
const sorter = (it) => {
if(typeof sortField == "function") {
return sortField(it)
}
return it[sortField];
}
const sq = dc.useMemo(() => q.sort((a, b) => sorter(a) > sorter(b) ? 1 : sorter(a) < sorter(b) ? -1 : 0), [q, sorter, b]);
return sq;
}
}