Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:02,100 --> 00:00:04,350
Now that we added our styling
2
00:00:04,350 --> 00:00:07,800
in our navigation bar let's work on the pages.
3
00:00:07,800 --> 00:00:10,480
Let's maybe start with the "All meetups" page
4
00:00:10,480 --> 00:00:15,480
and let's output a list of dummy meetups for the moment
5
00:00:15,550 --> 00:00:19,300
before we then make sure that we can add our own meetups.
6
00:00:20,434 --> 00:00:23,630
And for this I'll go to the all meetups js file.
7
00:00:23,630 --> 00:00:28,630
And the goal in there is to get a list of meetups later
8
00:00:29,350 --> 00:00:33,360
we will get it from a server by sending a HTTP request
9
00:00:33,360 --> 00:00:37,230
for the moment we'll work with some dummy meetups.
10
00:00:37,230 --> 00:00:40,190
And I then went to output those meetups.
11
00:00:40,190 --> 00:00:41,790
Now for this I'll, first of all
12
00:00:41,790 --> 00:00:46,430
add a constant name, dummy data, which we'll replace later
13
00:00:46,430 --> 00:00:48,853
which holds an array of dummy meetups.
14
00:00:49,970 --> 00:00:52,640
Now here I'll just add a bunch of JavaScript objects
15
00:00:52,640 --> 00:00:55,640
which hold the meetup data, things like the image
16
00:00:55,640 --> 00:00:59,670
the title, the description text and the address maybe.
17
00:00:59,670 --> 00:01:02,190
And for this you can definitely also use
18
00:01:02,190 --> 00:01:04,239
my code attachments there
19
00:01:04,239 --> 00:01:06,960
you'll find some prepared, dummy data.
20
00:01:06,960 --> 00:01:09,070
You can also prepare it your own one.
21
00:01:09,070 --> 00:01:11,550
Here I just have two dummy objects
22
00:01:11,550 --> 00:01:15,370
which have basically the same content, just different id's
23
00:01:15,370 --> 00:01:19,100
and different titles, but the same image, the same address
24
00:01:19,100 --> 00:01:22,140
the same description text, because of course it's not
25
00:01:22,140 --> 00:01:25,900
about the dummy data, but about what we do with it.
26
00:01:25,900 --> 00:01:28,010
Now, one word about that image.
27
00:01:28,010 --> 00:01:30,340
I got that from Wikipedia.
28
00:01:30,340 --> 00:01:32,660
You can of course bring your own images.
29
00:01:32,660 --> 00:01:36,860
Here I got this nice looking image here created
30
00:01:36,860 --> 00:01:39,420
by Thomas Wolf and not by me.
31
00:01:39,420 --> 00:01:42,910
So just to give him, due credits.
32
00:01:42,910 --> 00:01:44,920
And you can of course bring your own image.
33
00:01:44,920 --> 00:01:48,850
Just make sure that you simply get a URL
34
00:01:48,850 --> 00:01:51,090
to some image and store that in this image
35
00:01:51,090 --> 00:01:53,793
property of your dummy data points.
36
00:01:54,730 --> 00:01:56,530
Now we got the dummy data,
37
00:01:56,530 --> 00:01:59,430
now the goal is to output that data.
38
00:01:59,430 --> 00:02:04,340
So for this here in this div or section
39
00:02:04,340 --> 00:02:08,320
which we could also use, we can add an h1 tag let's say
40
00:02:08,320 --> 00:02:12,600
and say "all meetups" then below that we want to
41
00:02:12,600 --> 00:02:17,470
output this data, but of course not as code like this
42
00:02:17,470 --> 00:02:20,570
but instead as JSX elements.
43
00:02:20,570 --> 00:02:24,970
And for this we now need to learn how we can render a list
44
00:02:24,970 --> 00:02:29,400
of JSX elements, dynamically, how we can translate a list
45
00:02:29,400 --> 00:02:32,910
of data into a list of JSX elements.
46
00:02:32,910 --> 00:02:37,490
Because it is worth noting that in JSX,
47
00:02:37,490 --> 00:02:42,130
you can actually render an array JSX elements like this.
48
00:02:42,130 --> 00:02:45,440
So output a dynamic expression with curly braces
49
00:02:45,440 --> 00:02:47,070
then add an array.
50
00:02:47,070 --> 00:02:51,060
And in there you could have list items like item one
51
00:02:51,060 --> 00:02:53,143
and then as a second item, item two.
52
00:02:54,540 --> 00:02:57,100
And if you do that, those are rendered.
53
00:02:57,100 --> 00:03:02,100
So arrays are rendered correctly, automatically by React.
54
00:03:02,920 --> 00:03:05,900
And that's important to know, because that means
55
00:03:05,900 --> 00:03:09,150
that if we can translate this array of objects
56
00:03:09,150 --> 00:03:13,690
into an array of JSX elements, we can output it down there.
57
00:03:13,690 --> 00:03:16,250
And there is a way for translating
58
00:03:16,250 --> 00:03:20,650
an array into an array of different data in JavaScript.
59
00:03:20,650 --> 00:03:23,660
On that dummy data array, we can call the built in
60
00:03:23,660 --> 00:03:27,450
map method, which exists in JavaScript.
61
00:03:27,450 --> 00:03:31,030
And map allows us to execute a function,
62
00:03:31,030 --> 00:03:35,100
here I'm writing an arrow function on every element
63
00:03:35,100 --> 00:03:39,000
in that array, and it will get this element as a input.
64
00:03:39,000 --> 00:03:42,380
So in this case the meetup let's say as a input,
65
00:03:42,380 --> 00:03:45,407
automatically because this function is called
66
00:03:45,407 --> 00:03:47,780
"Automatically by JavaScript"
67
00:03:47,780 --> 00:03:51,120
and we then return the transformed data.
68
00:03:51,120 --> 00:03:55,630
And the result of calling map then is a new array full
69
00:03:55,630 --> 00:03:58,160
of that transformed data.
70
00:03:58,160 --> 00:04:00,990
And here we could say for every meetup object
71
00:04:00,990 --> 00:04:04,880
which we're getting, we want to return a list item.
72
00:04:04,880 --> 00:04:07,120
And hence we may be actually wrapped
73
00:04:07,120 --> 00:04:10,100
as all here with an unordered list.
74
00:04:10,100 --> 00:04:11,400
And in that list item
75
00:04:11,400 --> 00:04:14,880
we want to output data about that meetup,
76
00:04:14,880 --> 00:04:18,870
for example to begin with, to output the title.
77
00:04:18,870 --> 00:04:22,330
So here I'm dynamically outputting meetup title
78
00:04:22,330 --> 00:04:24,053
in this JSX code.
79
00:04:25,300 --> 00:04:27,750
So with that, we transform our array
80
00:04:27,750 --> 00:04:31,283
of objects into an array of li elements.
81
00:04:32,170 --> 00:04:35,460
And if we do that, just like this, and we reload
82
00:04:35,460 --> 00:04:38,750
we see this is a first and this is a second meetup.
83
00:04:38,750 --> 00:04:40,653
So that does work.
84
00:04:42,020 --> 00:04:45,430
Now, there is one important note about lists, though
85
00:04:45,430 --> 00:04:49,210
if you open the developer tools, you'll see a warning here
86
00:04:49,210 --> 00:04:52,713
that each child in a list should have a unique "key" prop.
87
00:04:53,670 --> 00:04:56,010
That is a requirement by React,
88
00:04:56,010 --> 00:05:00,880
which it needs to update and render lists efficiently.
89
00:05:00,880 --> 00:05:03,720
I dive deeper into that in my React course,
90
00:05:03,720 --> 00:05:05,320
for the moment it's enough to know
91
00:05:05,320 --> 00:05:08,600
that we should add the "key" prop here to the list item
92
00:05:08,600 --> 00:05:13,500
and then set this to some unique value per item.
93
00:05:13,500 --> 00:05:16,680
And we have a unique value for every list item here
94
00:05:16,680 --> 00:05:20,840
the IDs, the IDs are different for every item.
95
00:05:20,840 --> 00:05:23,540
So here we can then set this to meetup.id
96
00:05:24,450 --> 00:05:28,743
and with that we'll no longer get that warning if we reload.
97
00:05:29,960 --> 00:05:32,100
So that is how we can render a list
98
00:05:32,100 --> 00:05:34,770
of data simply by mapping it.
99
00:05:34,770 --> 00:05:38,300
And that is how you typically do render lists
100
00:05:38,300 --> 00:05:40,600
of data with React.
101
00:05:40,600 --> 00:05:43,500
But in the end, you can just render any array
102
00:05:43,500 --> 00:05:47,853
of JSX elements, no matter how you derived that array.
8383
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.