Open History to see the last commit
1import { queryOptions } from '@tanstack/react-query'
2β
3async function fetchProjects(): Promise<
4 Array<{ name: string; full_name: string }>
5> {
6 console.info('Fetching projects')
7β
8 const response = await fetch(
9 `https://api.github.com/users/TanStack/repos?sort=updated`,
10 )
11 if (!response.ok) throw new Error('Failed to fetch projects')
12 await new Promise((r) => setTimeout(r, 1000))
13 return await response.json()
14}
15β
16async function fetchProject(id: string): Promise<{
17 forks_count: number
18 stargazers_count: number
19 watchers_count: number
20}> {
21 console.info('Fetching project:', id)
22β
23 const response = await fetch(`https://api.github.com/repos/${id}`)
24 if (!response.ok) throw new Error('Failed to fetch project')
25 await new Promise((r) => setTimeout(r, 1000))
26 return await response.json()
27}
28β
29export const projectsQueryOptions = queryOptions({
30 queryKey: ['projects'],
31 queryFn: fetchProjects,
32})
33β
34export const projectQueryOptions = (id: string) =>
35 queryOptions({
36 queryKey: ['project', id],
37 queryFn: () => fetchProject(id),
38 })