Skip to content

Instantly share code, notes, and snippets.

@abarreir
Created October 16, 2023 08:54
Show Gist options
  • Save abarreir/3a840040c7948719655645aaad24a0d5 to your computer and use it in GitHub Desktop.
Save abarreir/3a840040c7948719655645aaad24a0d5 to your computer and use it in GitHub Desktop.
Navigation-aware ant design table
import { Table as AntTable } from "antd";
import { TableProps } from "antd/es/table";
import { useSearchParams } from "react-router-dom";
export default function Table<RecordType extends object = any>(
props: TableProps<RecordType>
) {
let [searchParams, setSearchParams] = useSearchParams();
let current = searchParams.has("page")
? parseInt(searchParams.get("page")!)
: undefined;
return (
<AntTable
{...props}
pagination={{
...props.pagination,
current,
onChange: (page, _) =>
setSearchParams({ page: `${page}` }, { replace: true }),
}}
/>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment