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

index.js

35 lines844 Bytes

1import React from 'react'
2import Link from 'next/link'
3import fetch from '../libs/fetch'
4​
5import { useQuery } from 'react-query'
6​
7export default () => {
8 const { data, isLoading, isFetching } = useQuery(false && 'projects', () =>
9 fetch('/api/data')
10 )
11​
12 return (
13 <div style={{ textAlign: 'center' }}>
14 <h1>Trending Projects</h1>
15 <div>
16 {isLoading ? (
17 'Loading...'
18 ) : data ? (
19 <>
20 <div>
21 {data.map(project => (
22 <p key={project}>
23 <Link href="/[user]/[repo]" as={`/${project}`}>
24 <a>{project}</a>
25 </Link>
26 </p>
27 ))}
28 </div>
29 <div>{isFetching ? 'Background Updating...' : ' '}</div>
30 </>
31 ) : null}
32 </div>
33 </div>
34 )