Open History to see the last commit
1import React from 'react'
2import { dehydrate, QueryClient } from '@tanstack/react-query'
3import { Layout, Header, InfoBox, PostList } from '../components'
4import { fetchPosts } from '../hooks'
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 )
14}
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 }
29}
30
31export default Home