Newer
Older
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
40
41
import { GetStaticPaths, GetStaticProps } from "next";
import { dehydrate, QueryClient } from "react-query";
import {
PageList,
getBooks,
getBooksPath,
} from "../../../components/book/PageList";
import { PagedCollection } from "../../../types/collection";
import { Book } from "../../../types/Book";
import { fetch, getCollectionPaths } from "../../../utils/dataAccess";
export const getStaticProps: GetStaticProps = async ({
params: { page } = {},
}) => {
const queryClient = new QueryClient();
await queryClient.prefetchQuery(getBooksPath(page), getBooks(page));
return {
props: {
dehydratedState: dehydrate(queryClient),
},
revalidate: 1,
};
};
export const getStaticPaths: GetStaticPaths = async () => {
const response = await fetch<PagedCollection<Book>>("/books");
const paths = await getCollectionPaths(
response,
"books",
"/books/page/[page]"
);
return {
paths,
fallback: true,
};
};
export default PageList;