Open History to see the last commit
1import { infiniteQueryOptions } from '@tanstack/react-query'
2β
3const fetchProjects = async (
4 cursor: number,
5): Promise<{
6 data: Array<{ name: string; id: number }>
7 previousId: number | null
8 nextId: number | null
9}> => {
10 const response = await fetch(`/api/projects?cursor=${cursor}`)
11 if (!response.ok) throw new Error('Failed to fetch projects')
12 return await response.json()
13}
14β
15export const projectsInfiniteQueryOptions = infiniteQueryOptions({
16 queryKey: ['projects'],
17 queryFn: ({ pageParam }) => fetchProjects(pageParam),
18 initialPageParam: 0,
19 getPreviousPageParam: (firstPage) => firstPage.previousId,
20 getNextPageParam: (lastPage) => lastPage.nextId,
21})