mirror of
https://github.com/outline/outline.git
synced 2026-06-13 03:14:59 +03:00
perf: Remove unneccesary location subscription (#12116)
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import type { ColumnSort } from "@tanstack/react-table";
|
||||
import { useCallback } from "react";
|
||||
import { useHistory, useLocation } from "react-router-dom";
|
||||
import useQuery from "~/hooks/useQuery";
|
||||
import { useHistory } from "react-router-dom";
|
||||
import lazyWithRetry from "~/utils/lazyWithRetry";
|
||||
import type { Props as TableProps } from "./Table";
|
||||
|
||||
@@ -10,21 +9,21 @@ const Table = lazyWithRetry(() => import("~/components/Table"));
|
||||
export type Props<T> = Omit<TableProps<T>, "onChangeSort">;
|
||||
|
||||
export function SortableTable<T>(props: Props<T>) {
|
||||
const location = useLocation();
|
||||
const history = useHistory();
|
||||
const params = useQuery();
|
||||
|
||||
const handleChangeSort = useCallback(
|
||||
(sort: ColumnSort) => {
|
||||
const { pathname, search } = history.location;
|
||||
const params = new URLSearchParams(search);
|
||||
params.set("sort", sort.id);
|
||||
params.set("direction", sort.desc ? "desc" : "asc");
|
||||
|
||||
history.replace({
|
||||
pathname: location.pathname,
|
||||
pathname,
|
||||
search: params.toString(),
|
||||
});
|
||||
},
|
||||
[params, history, location.pathname]
|
||||
[history]
|
||||
);
|
||||
|
||||
return <Table onChangeSort={handleChangeSort} {...props} />;
|
||||
|
||||
Reference in New Issue
Block a user