queries/search: use flattenPages util

This commit is contained in:
Alex Gleason 2022-12-12 12:10:39 -06:00
parent 15594df644
commit 502f9d9f47
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7

View file

@ -3,7 +3,7 @@ import { useInfiniteQuery } from '@tanstack/react-query';
import { getNextLink } from 'soapbox/api';
import { useApi } from 'soapbox/hooks';
import { Account } from 'soapbox/types/entities';
import { PaginatedResult } from 'soapbox/utils/queries';
import { flattenPages, PaginatedResult } from 'soapbox/utils/queries';
export default function useAccountSearch(q: string) {
const api = useApi();
@ -42,10 +42,7 @@ export default function useAccountSearch(q: string) {
},
});
const data = queryInfo.data?.pages.reduce<Account[]>(
(prev: Account[], curr) => [...prev, ...curr.result],
[],
);
const data = flattenPages(queryInfo.data);
return {
...queryInfo,