Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:01,666 --> 00:00:03,820
Now that was a lot of talking
2
00:00:03,820 --> 00:00:05,953
about getStaticProps and getServerSideProps.
3
00:00:07,080 --> 00:00:09,717
But these are two key concepts,
4
00:00:09,717 --> 00:00:13,850
two key functions built into next JS,
5
00:00:13,850 --> 00:00:15,720
which you need all the time.
6
00:00:15,720 --> 00:00:18,480
As you'll see in my full course, for example
7
00:00:18,480 --> 00:00:20,900
when we work on that full block project,
8
00:00:20,900 --> 00:00:23,970
we use those functions everywhere.
9
00:00:23,970 --> 00:00:25,943
They are super important.
10
00:00:26,800 --> 00:00:27,977
And hence, let's also use them
11
00:00:27,977 --> 00:00:30,400
for the MeetupDetail page now.
12
00:00:30,400 --> 00:00:33,460
For the new Meetup page, as explained earlier
13
00:00:33,460 --> 00:00:36,830
we don't need them because here we don't need any data
14
00:00:36,830 --> 00:00:39,472
and therefore there is no need to add getStaticProps.
15
00:00:39,472 --> 00:00:42,360
It's really only there to fetch data
16
00:00:42,360 --> 00:00:43,888
for the pre-generated page
17
00:00:43,888 --> 00:00:46,470
if that page needs any data
18
00:00:46,470 --> 00:00:48,430
and therefore we don't need it here
19
00:00:48,430 --> 00:00:50,360
but on the MeetupDetail page of course.
20
00:00:50,360 --> 00:00:52,734
We do have data that is needed
21
00:00:52,734 --> 00:00:56,900
for the moment hard-coded data, but that will change.
22
00:00:56,900 --> 00:00:58,885
And hence, here on MeetupDetails,
23
00:00:58,885 --> 00:01:03,885
we also want to use getStaticProps or getServerSideProps.
24
00:01:04,940 --> 00:01:06,690
Now, which one is better?
25
00:01:06,690 --> 00:01:08,985
It depends on how often your data changes
26
00:01:08,985 --> 00:01:12,170
and if you need access to the request object.
27
00:01:12,170 --> 00:01:14,450
And here it's probably fair to assume
28
00:01:14,450 --> 00:01:18,020
that the meetupData does not change very often.
29
00:01:18,020 --> 00:01:20,605
Indeed this app doesn't even have a feature
30
00:01:20,605 --> 00:01:23,230
for changing the meetupData.
31
00:01:23,230 --> 00:01:24,655
We can only add Meetups
32
00:01:24,655 --> 00:01:28,310
but even if it would have a change feature,
33
00:01:28,310 --> 00:01:30,351
it would probably not be the case
34
00:01:30,351 --> 00:01:34,330
that a Meetup changes multiple times every second.
35
00:01:34,330 --> 00:01:36,090
And therefore, for to MeetupDetails
36
00:01:36,090 --> 00:01:37,820
I would argue that again,
37
00:01:37,820 --> 00:01:41,433
getStaticProps is better than getServerSideProps.
38
00:01:43,096 --> 00:01:46,080
So here we export getStaticProps
39
00:01:46,080 --> 00:01:48,410
and we can turn it into an async function
40
00:01:48,410 --> 00:01:50,770
if we want to use async await.
41
00:01:50,770 --> 00:01:55,770
And then here we could fetch the data for a single meetup.
42
00:01:56,350 --> 00:02:00,150
And then we can of course return as object with the props.
43
00:02:00,150 --> 00:02:03,057
And here we could have our meetupData prop
44
00:02:03,057 --> 00:02:04,999
or however you want to name it,
45
00:02:04,999 --> 00:02:07,804
which could again be a nested object
46
00:02:07,804 --> 00:02:11,100
where we then have this data here,
47
00:02:11,100 --> 00:02:13,550
so where we have that image.
48
00:02:13,550 --> 00:02:16,758
So we have image set to the string
49
00:02:16,758 --> 00:02:21,170
where we have ID if we needed, M1.
50
00:02:21,170 --> 00:02:22,863
Where we have the title,
51
00:02:23,906 --> 00:02:25,753
First Meetup here.
52
00:02:28,480 --> 00:02:33,480
Where we have the address and that's this address
53
00:02:33,690 --> 00:02:38,690
and where we then also have the description here,
54
00:02:38,690 --> 00:02:40,470
this description.
55
00:02:40,470 --> 00:02:42,130
That could be the props data
56
00:02:42,130 --> 00:02:45,566
which we send to this component function.
57
00:02:45,566 --> 00:02:50,566
But here we'll actually have a slight problem.
58
00:02:50,580 --> 00:02:53,810
Keep in mind that this is a dynamic page.
59
00:02:53,810 --> 00:02:57,480
So when we reach out to an API to fetch the data
60
00:02:57,480 --> 00:02:58,775
for a single meetup,
61
00:02:58,775 --> 00:03:02,640
we need a way of identifying that meetup.
62
00:03:02,640 --> 00:03:05,230
We need its ID for example.
63
00:03:05,230 --> 00:03:10,230
Now the ID thankfully is encoded into URL.
64
00:03:10,740 --> 00:03:12,250
And therefore, we did learn
65
00:03:12,250 --> 00:03:16,200
that we can use stead use router hook to get access
66
00:03:16,200 --> 00:03:20,700
to this router object and then use the query property there.
67
00:03:20,700 --> 00:03:24,136
That's what we did earlier in this course.
68
00:03:24,136 --> 00:03:26,380
But the problem with that is
69
00:03:26,380 --> 00:03:29,070
that the use router hook can only be used
70
00:03:29,070 --> 00:03:32,113
in the component function, not in geStaticProps.
71
00:03:33,020 --> 00:03:37,180
That's not a function where you can use react hooks.
72
00:03:37,180 --> 00:03:39,200
So we can't get to the meetup ID
73
00:03:39,200 --> 00:03:43,025
from the URL with help of use router in here.
74
00:03:43,025 --> 00:03:45,360
But we also don't need to.
75
00:03:45,360 --> 00:03:48,070
Because you might remember this context parameter,
76
00:03:48,070 --> 00:03:49,590
which I mentioned.
77
00:03:49,590 --> 00:03:53,290
I showed it to you on getServerSideProps,
78
00:03:53,290 --> 00:03:55,660
but I mentioned that it also actually exists
79
00:03:55,660 --> 00:03:57,183
on getStaticProps.
80
00:03:58,520 --> 00:04:01,650
Now, when we accept it on getStaticProps,
81
00:04:01,650 --> 00:04:04,880
context will not hold request and response,
82
00:04:04,880 --> 00:04:09,700
but it will, for example, have a parans key.
83
00:04:09,700 --> 00:04:12,330
So there will be context.parans,
84
00:04:12,330 --> 00:04:16,228
and that will be an object where our identifiers
85
00:04:16,228 --> 00:04:19,652
between the square brackets will be properties
86
00:04:19,652 --> 00:04:22,840
and the values will be the actual values
87
00:04:22,840 --> 00:04:24,923
encoded in the URL.
88
00:04:25,860 --> 00:04:29,230
So our meetup ID, for example, could be accessed
89
00:04:29,230 --> 00:04:31,363
with context.parans.meetupid.
90
00:04:32,820 --> 00:04:35,768
Meetup ID because that's the identifier I have
91
00:04:35,768 --> 00:04:37,374
between the square brackets.
92
00:04:37,374 --> 00:04:40,481
And that would then be the concrete meetup ID
93
00:04:40,481 --> 00:04:42,923
for which we're displaying this meetup.
94
00:04:43,960 --> 00:04:48,290
I can console log this here inside of getStaticProps
95
00:04:48,290 --> 00:04:51,303
so that we can see that this really works.
96
00:04:51,303 --> 00:04:55,249
And then it's this meetup ID, which we could set as ID here
97
00:04:55,249 --> 00:04:58,493
if we want to expose it to the component function.
98
00:04:59,610 --> 00:05:01,650
With that if we saved this
99
00:05:01,650 --> 00:05:05,598
and visit the detailed page of a single meetup,
100
00:05:05,598 --> 00:05:10,248
we get an error though, getStaticProps is required.
101
00:05:10,248 --> 00:05:12,413
Now, what's this error about?
7792
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.