Skip to content

Commit b4309ee

Browse files
committed
Add an isr route to the playground
1 parent 2a3e896 commit b4309ee

File tree

1 file changed

+30
-0
lines changed
  • examples/playground/app/isr/[id]

1 file changed

+30
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Imported from https://nextjs.org/docs/app/building-your-application/data-fetching/incremental-static-regeneration
2+
interface Post {
3+
id: string;
4+
title: string;
5+
content: string;
6+
}
7+
8+
// Next.js will invalidate the cache when a
9+
// request comes in, at most once every 1 hour.
10+
export const revalidate = 3600;
11+
12+
// We'll prerender only the params from `generateStaticParams` at build time.
13+
// If a request comes in for a path that hasn't been generated,
14+
// Next.js will server-render the page on-demand.
15+
export const dynamicParams = false; // or false, to 404 on unknown paths
16+
17+
export async function generateStaticParams() {
18+
return [{ id: "1" }, { id: "2" }, { id: "3" }];
19+
}
20+
21+
export default async function Page({ params }: { params: Promise<{ id: string }> }) {
22+
const id = (await params).id;
23+
const post: Post = await fetch(`https://api.vercel.app/blog/${id}`).then((res) => res.json());
24+
return (
25+
<main>
26+
<h1>{post.title}</h1>
27+
<p>{post.content}</p>
28+
</main>
29+
);
30+
}

0 commit comments

Comments
 (0)