mirror of
https://github.com/jeffvli/feishin.git
synced 2026-06-15 16:04:19 +02:00
fix list filters
This commit is contained in:
@@ -1,13 +1,18 @@
|
||||
import { parseAsInteger, useQueryState } from 'nuqs';
|
||||
import { useMemo } from 'react';
|
||||
import { useSearchParams } from 'react-router';
|
||||
|
||||
import { parseIntParam, setSearchParam } from '/@/renderer/utils/query-params';
|
||||
|
||||
export const useItemListPagination = () => {
|
||||
const [currentPage, setCurrentPage] = useQueryState(
|
||||
'currentPage',
|
||||
parseAsInteger.withDefault(0),
|
||||
);
|
||||
const [searchParams, setSearchParams] = useSearchParams();
|
||||
|
||||
const currentPage = useMemo(() => {
|
||||
const value = parseIntParam(searchParams, 'currentPage');
|
||||
return value ?? 0;
|
||||
}, [searchParams]);
|
||||
|
||||
const onChange = (index: number) => {
|
||||
setCurrentPage(index);
|
||||
setSearchParams((prev) => setSearchParam(prev, 'currentPage', index), { replace: true });
|
||||
};
|
||||
|
||||
return { currentPage, onChange };
|
||||
|
||||
Reference in New Issue
Block a user