refactoring: improvements for lighthouse

This commit is contained in:
ner committed 2024-10-21 15:35:08 +03:00
1 parent f2f242a684
commit 38aebcbe28
27 files changed
+132 -93

No files matched your search

+6 -3
View File
@@ -1,14 +1,17 @@
import { useMemo } from 'react';
import { QueryKey, useInfiniteQuery } from '@tanstack/react-query';
import { QueryKey, useInfiniteQuery, useSuspenseInfiniteQuery } from '@tanstack/react-query';
interface Props {
suspense?: boolean;
queryKey: QueryKey;
enabled?: boolean;
queryFn: ({ page }: { page: string }) => Promise<Pagination<Show>>;
}
const useInfiniteList = ({ queryKey, queryFn, enabled }: Props) => {
const { data, hasNextPage, fetchNextPage, isFetched, isLoading } = useInfiniteQuery({
const useInfiniteList = ({ queryKey, queryFn, enabled, suspense }: Props) => {
const { data, hasNextPage, fetchNextPage, isFetched, isLoading } = (
suspense ? useSuspenseInfiniteQuery : useInfiniteQuery
)({
enabled,
queryKey,
queryFn: ({ pageParam }) => queryFn({ page: pageParam }),