bigbuffet-rw/packages/pl-hooks/lib/utils/queries.ts
marcin mikołajczak 8a047d7c3a work on turning pl-hooks into a separate library
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
2024-10-13 00:15:58 +02:00

12 lines
401 B
TypeScript

import type { InfiniteData } from '@tanstack/react-query';
import type { PaginatedResponse } from 'pl-api';
/** Flatten paginated results into a single array. */
const flattenPages = <T>(queryData: InfiniteData<Pick<PaginatedResponse<T>, 'items'>> | undefined) => {
return queryData?.pages.reduce<T[]>(
(prev: T[], curr) => [...prev, ...(curr.items)],
[],
);
};
export { flattenPages };