/
[repo].js
executable file
路39 lines (35 loc) 路 956 Bytes
/
[repo].js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import React from 'react'
import Link from 'next/link'
import fetch from '../../libs/fetch'
import { useQuery } from '@tanstack/react-query'
export default () => {
const id =
typeof document !== 'undefined' ? window.location.pathname.slice(1) : ''
const { status, data, error, isFetching } = useQuery(['team', id], () =>
fetch('/api/data?id=' + id),
)
return (
<div style={{ textAlign: 'center' }}>
<h1>{id}</h1>
{status === 'loading' ? (
'Loading...'
) : status === 'error' ? (
<span>Error: {error.message}</span>
) : (
<>
<div>
<p>forks: {data.forks_count}</p>
<p>stars: {data.stargazers_count}</p>
<p>watchers: {data.watchers}</p>
</div>
<div>{isFetching ? 'Background Updating...' : ' '}</div>
</>
)}
<br />
<br />
<Link href="/">
<a>Back</a>
</Link>
</div>
)
}