work on turning pl-hooks into a separate library
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
12
packages/pl-hooks/lib/utils/queries.ts
Normal file
12
packages/pl-hooks/lib/utils/queries.ts
Normal file
@ -0,0 +1,12 @@
|
||||
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 };
|
||||
Reference in New Issue
Block a user