Skip to content

Commit

Permalink
Fixes pagination not working in Location Management (PaginatedList
Browse files Browse the repository at this point in the history
…component) (#6462)

* PaginatedList: fix `offset` not included in qParams

* fix error message
  • Loading branch information
rithviknishad authored Oct 25, 2023
1 parent 0ea1a1f commit 30aa4df
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/CAREUI/misc/PaginatedList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function useContextualized<TItem>() {
const ctx = useContext(context);

if (ctx === null) {
throw new Error("PaginatedList must be used within a PaginatedList");
throw new Error("Component must be used within a PaginatedList");
}

return ctx as PaginatedListContext<TItem>;
Expand All @@ -42,11 +42,15 @@ export default function PaginatedList<TItem extends object>({
perPage = DEFAULT_PER_PAGE_LIMIT,
...queryOptions
}: Props<TItem>) {
const [currentPage, setPage] = useState(1);
const query = useQuery(route, {
...queryOptions,
query: { ...queryOptions.query, limit: perPage },
query: {
...queryOptions.query,
limit: perPage,
offset: (currentPage - 1) * perPage,
},
});
const [currentPage, setPage] = useState(1);

const items = query.data?.results ?? [];

Expand Down

0 comments on commit 30aa4df

Please sign in to comment.