Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:02,210 --> 00:00:03,770
So now we had a look at
2
00:00:03,770 --> 00:00:07,640
getStaticProps and getStaticPaths.
3
00:00:07,640 --> 00:00:10,110
And these two are working together.
4
00:00:10,110 --> 00:00:12,010
You don't always need both.
5
00:00:12,010 --> 00:00:15,870
In the case of index.js, we only needed getStaticProps.
6
00:00:15,870 --> 00:00:19,060
But for dynamic pages, that should be pre-generated,
7
00:00:19,060 --> 00:00:20,930
you do need both.
8
00:00:20,930 --> 00:00:24,970
Now you might recall that earlier in this module,
9
00:00:24,970 --> 00:00:27,610
at the beginning of this course section,
10
00:00:27,610 --> 00:00:29,290
I showed you this slide
11
00:00:29,290 --> 00:00:34,280
and I referred to two forms of pre-rendering:
12
00:00:34,280 --> 00:00:38,120
static generation and server-side rendering.
13
00:00:38,120 --> 00:00:41,170
Now what we had a look at thus far,
14
00:00:41,170 --> 00:00:43,550
that's static generation
15
00:00:43,550 --> 00:00:47,570
because we statically pre-generate pages.
16
00:00:47,570 --> 00:00:49,770
Even though it's not fully static
17
00:00:49,770 --> 00:00:52,410
because of incremental static generation,
18
00:00:52,410 --> 00:00:53,920
which I also explained,
19
00:00:53,920 --> 00:00:57,343
but generally pages are pre-generated.
20
00:00:58,240 --> 00:01:00,080
And that is really important.
21
00:01:00,080 --> 00:01:04,989
Inside of getStaticProps and also inside of getStaticPaths,
22
00:01:04,989 --> 00:01:09,090
we don't have access to the actual request
23
00:01:09,090 --> 00:01:10,800
which is incoming.
24
00:01:10,800 --> 00:01:13,820
Because these functions are not called
25
00:01:13,820 --> 00:01:17,720
for the actual request, at least not only.
26
00:01:17,720 --> 00:01:19,940
With incremental static generation,
27
00:01:19,940 --> 00:01:23,370
they are also called for incoming requests
28
00:01:23,370 --> 00:01:27,500
at least sometimes if they need to be re-validated
29
00:01:27,500 --> 00:01:32,400
but they are generally called when your project is built.
30
00:01:32,400 --> 00:01:34,950
So inside of getStaticProps,
31
00:01:34,950 --> 00:01:39,950
you don't have access to the actual incoming request.
32
00:01:40,070 --> 00:01:43,940
Now, very often, you also don't need access.
33
00:01:43,940 --> 00:01:47,570
For example, here in the examples I showed you thus far,
34
00:01:47,570 --> 00:01:50,560
we don't need access to the actual request,
35
00:01:50,560 --> 00:01:52,510
which is reaching the server.
36
00:01:52,510 --> 00:01:55,670
But sometimes static generation is not enough
37
00:01:55,670 --> 00:01:59,930
and instead, you need real server-side rendering,
38
00:01:59,930 --> 00:02:04,930
which means that you do need to pre-render a page
39
00:02:05,000 --> 00:02:07,570
for every incoming request.
40
00:02:07,570 --> 00:02:09,710
So not at most every second
41
00:02:09,710 --> 00:02:12,760
but really for every incoming request
42
00:02:12,760 --> 00:02:17,760
and/or you need access to the concrete request object
43
00:02:17,840 --> 00:02:19,640
that is reaching the server.
44
00:02:19,640 --> 00:02:23,220
Because, for example, you need to extract cookies.
45
00:02:23,220 --> 00:02:26,700
And that is something we're also going to see later
46
00:02:26,700 --> 00:02:29,930
in the course when we talk about authentication
47
00:02:29,930 --> 00:02:32,640
but I already want to introduce you
48
00:02:32,640 --> 00:02:36,190
to real server-side rendering here.
49
00:02:36,190 --> 00:02:38,050
The idea is simple.
50
00:02:38,050 --> 00:02:39,440
NextJS also supports this run real server-side code use case
51
00:02:39,440 --> 00:02:44,440
NextJS also supports this run real server-side code use case
52
00:02:44,730 --> 00:02:47,550
which means it gives you a function
53
00:02:47,550 --> 00:02:51,070
which you can add to your page component files,
54
00:02:51,070 --> 00:02:52,828
which is then really executed
55
00:02:52,828 --> 00:02:57,740
whenever a request for this page reaches the server.
56
00:02:57,740 --> 00:03:01,280
So that's then not pre-generated in advance
57
00:03:01,280 --> 00:03:04,660
during build time or every couple of seconds
58
00:03:04,660 --> 00:03:08,860
but it's really code that runs on the server only,
59
00:03:08,860 --> 00:03:11,440
so only after you deployed it,
60
00:03:11,440 --> 00:03:16,440
and which is then re-executed for every incoming request.
61
00:03:17,060 --> 00:03:20,426
And that code is added to a function called
62
00:03:20,426 --> 00:03:22,593
getServerSideProps.
63
00:03:23,550 --> 00:03:27,630
Just like getStaticProps, it's a async function.
64
00:03:27,630 --> 00:03:30,610
It needs to be called exactly like this
65
00:03:30,610 --> 00:03:32,650
and it needs to be exported.
66
00:03:32,650 --> 00:03:36,290
And you can only add it to your page component files.
67
00:03:36,290 --> 00:03:38,600
But then if you do have such a function
68
00:03:38,600 --> 00:03:40,440
in a page component file,
69
00:03:40,440 --> 00:03:44,853
NextJS will execute that function and it will execute it
70
00:03:44,853 --> 00:03:48,540
whenever a request for this page is made.
71
00:03:48,540 --> 00:03:53,116
And therefore, you should only use either getStaticProps,
72
00:03:53,116 --> 00:03:54,910
what we saw thus far,
73
00:03:54,910 --> 00:03:59,730
or getServerSideProps because they kind of clash.
74
00:03:59,730 --> 00:04:02,110
They fulfill the same purpose.
75
00:04:02,110 --> 00:04:04,440
They get props for the component
76
00:04:04,440 --> 00:04:08,720
so that NextJS is then able to render that component
77
00:04:08,720 --> 00:04:11,863
but they run at different points of time.
6070
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.