Improve swr key handling

This commit is contained in:
Sam Becker 2024-04-26 12:58:00 -05:00
parent 4b358249a9
commit 11878f807c
3 changed files with 6 additions and 1 deletions

View File

@ -38,6 +38,7 @@ export default async function GridPage() {
<PhotoGrid {...{ photos, photoPriority: true }} />
{photos.length >= INFINITE_SCROLL_MULTIPLE_GRID &&
<InfinitePhotoScroll
swrKey={photos[0].id}
type='grid'
initialOffset={INFINITE_SCROLL_MULTIPLE_GRID}
itemsPerPage={INFINITE_SCROLL_MULTIPLE_GRID}

View File

@ -33,6 +33,8 @@ export default async function HomePage() {
<PhotosLarge {...{ photos }} />
{photos.length >= INFINITE_SCROLL_MULTIPLE_HOME &&
<InfinitePhotoScroll
swrKey={photos[0].id}
type="full-frame"
initialOffset={INFINITE_SCROLL_MULTIPLE_HOME}
itemsPerPage={INFINITE_SCROLL_MULTIPLE_HOME}
/>}

View File

@ -17,12 +17,14 @@ export type RevalidatePhoto = (
) => Promise<any>;
export default function InfinitePhotoScroll({
swrKey,
type = 'full-frame',
initialOffset = 0,
itemsPerPage = 12,
prefetch = true,
triggerOnView = true,
}: {
swrKey: string
type?: 'full-frame' | 'grid'
initialOffset?: number
itemsPerPage?: number
@ -30,7 +32,7 @@ export default function InfinitePhotoScroll({
triggerOnView?: boolean
debug?: boolean
}) {
const key = type;
const key = `${swrKey}-${type}`;
const buttonContainerRef = useRef<HTMLDivElement>(null);