forked from guydumais/next-page-rendering
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstatic-site-generation.tsx
More file actions
46 lines (42 loc) · 1.21 KB
/
static-site-generation.tsx
File metadata and controls
46 lines (42 loc) · 1.21 KB
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
42
43
44
45
46
// Next.js libraries
import Head from "next/head";
// Custom Components
import BackToHome from "components/BackToHome";
// Page component
export default function StaticSideGeneration({ jsonData }) {
return (
<>
<Head>
<title>Static-Site Generation (SSG) • Guy Dumais</title>
<meta
name="description"
content="Example page using Static-Site Generation (SSG) with Next.js 12 and React 17"
/>
<meta name="viewport" content="initial-scale=1.0, width=device-width" />
</Head>
<BackToHome />
<h1>Static-Site Generation (SSG)</h1>
<p>
Data fetched at build-time on the server-side before sending to the
client.
</p>
<ul>
{jsonData.data.map((e) => (
<li key={e.id}>{e.email}</li>
))}
</ul>
</>
);
}
// This function gets called at build time on server-side.
// It won't be called on client-side, so you can even do
// direct database queries.
export async function getStaticProps() {
const res = await fetch("https://reqres.in/api/users?page=2");
const jsonData = await res.json();
return {
props: {
jsonData, // will be passed to the page component as props
},
};
}