File tree 1 file changed +45
-0
lines changed
demos/default/pages/getStaticProps/withRevalidate/withFallbackBlocking
1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change
1
+ import Link from 'next/link'
2
+
3
+ const Show = ( { show, time } ) => (
4
+ < div >
5
+ < p > This page uses getStaticProps() to pre-fetch a TV show.</ p >
6
+ < p > Ids 1 and 2 are prerendered</ p >
7
+ < hr />
8
+
9
+ < h1 > Show #{ show . id } </ h1 >
10
+ < p > { show . name } </ p >
11
+ < p > Rendered at { time } </ p >
12
+ < hr />
13
+
14
+ < Link href = "/" >
15
+ < a > Go back home</ a >
16
+ </ Link >
17
+ </ div >
18
+ )
19
+
20
+ export async function getStaticPaths ( ) {
21
+ // Set the paths we want to pre-render
22
+ const paths = [ { params : { id : '1' } } , { params : { id : '2' } } ]
23
+
24
+ // We'll pre-render only these paths at build time.
25
+
26
+ return { paths, fallback : 'blocking' }
27
+ }
28
+
29
+ export async function getStaticProps ( { params } ) {
30
+ // The ID to render
31
+ const { id } = params
32
+
33
+ const res = await fetch ( `https://api.tvmaze.com/shows/${ id } ` )
34
+ const data = await res . json ( )
35
+ const time = new Date ( ) . toLocaleTimeString ( )
36
+ return {
37
+ props : {
38
+ show : data ,
39
+ time,
40
+ } ,
41
+ revalidate : 60 ,
42
+ }
43
+ }
44
+
45
+ export default Show
You can’t perform that action at this time.
0 commit comments