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

index.tsx

31 lines679 Bytes

1import React from 'react'
2import { QueryClient, dehydrate } from '@tanstack/react-query'
3import { Header, InfoBox, Layout, PostList } from '../components'
4import { fetchPosts } from '../hooks/usePosts'
5​
6const Home = () => {
7 return (
8 <Layout>
9 <Header />
10 <InfoBox>ℹ️ This page shows how to use SSG with React-Query.</InfoBox>
11 <PostList />
12 </Layout>
13 )
15​
16export async function getStaticProps() {
17 const queryClient = new QueryClient()
18​
19 await queryClient.prefetchQuery({
20 queryKey: ['posts', 10],
21 queryFn: () => fetchPosts(10),
22 })
23​
24 return {
25 props: {
26 dehydratedState: dehydrate(queryClient),
27 },
28 }
30​
31export default Home