perf: Remove unneccesary location subscription (#12116)

This commit is contained in:
Tom Moor
2026-04-19 16:18:52 -04:00
committed by GitHub
parent ce409c0a8a
commit c52c96dc96
+5 -6
View File
@@ -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} />;