forked from guydumais/next-page-rendering
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclient-side-rendering.tsx
More file actions
45 lines (39 loc) · 1.08 KB
/
Copy pathclient-side-rendering.tsx
File metadata and controls
45 lines (39 loc) · 1.08 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
// React
import { useEffect, useState } from "react";
// Next.js
import Head from "next/head";
import Link from "next/link";
// Custom Components
import BackToHome from "components/BackToHome";
// Page component
export default function ClientSideRendered() {
const [state, setState] = useState([] as any);
const getData = async () => {
const res = await fetch("https://reqres.in/api/users?page=2");
const jsonData = await res.json();
setState(jsonData);
};
useEffect(() => {
getData();
}, []);
return (
<>
<Head>
<title>Client-Side Rendering (CSR) • Guy Dumais</title>
<meta
name="description"
content="Example page using Client-Side Rendering (CSR) with Next.js 12 and React 17"
/>
<meta name="viewport" content="initial-scale=1.0, width=device-width" />
</Head>
<BackToHome />
<h1>Client-Side Rendering (CSR)</h1>
<p>Data fetched on the client-side only.</p>
<ul>
{state.data?.map((e) => (
<li key={e.id}>{e.email}</li>
))}
</ul>
</>
);
}