Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

api.ts

19 lines514 Bytes

1import { queryOptions } from '@tanstack/react-query'
2​
3const fetchProjects = async (
4 page = 0,
5): Promise<{
6 projects: Array<{ name: string; id: number }>
7 hasMore: boolean
8}> => {
9 const response = await fetch(`/api/projects?page=${page}`)
10 if (!response.ok) throw new Error('Failed to fetch projects')
11 return await response.json()
13​
14export const projectsQueryOptions = (page: number) =>
15 queryOptions({
16 queryKey: ['projects', page],
17 queryFn: () => fetchProjects(page),
18 staleTime: 5000,
19 })