fix: proper prefetch

This commit is contained in:
ner committed 2024-10-29 19:39:41 +02:00
1 parent c9ca262da8
commit 3b954279f7
9 files changed
+12 -15

No files matched your search

+3 -1
View File
@@ -5,6 +5,7 @@ import { atom, getDefaultStore, useAtom } from 'jotai';
import randomQuery from '@/data/queries/random';
import useInfiniteList from '@/hooks/useInfiniteList';
import useMounted from '@/hooks/useMounted';
const indexAtom = atom(0);
@@ -15,9 +16,10 @@ interface Props {
}
const useRandomMovie = ({ page }: Props) => {
const isMounted = useMounted();
const [index, setIndex] = useAtom(indexAtom);
const { shows: movies, fetchNextPage } = useInfiniteList(randomQuery({ page }));
const { shows: movies, fetchNextPage } = useInfiniteList(randomQuery({ page, suspense: false }));
if (movies.length && !movies[index]) {
setIndex(0);