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,160
Now, rendering our list like this
2
00:00:04,160 --> 00:00:06,210
is of course not our goal.
3
00:00:06,210 --> 00:00:08,090
We want to render a more beautiful,
4
00:00:08,090 --> 00:00:10,220
a more good looking list.
5
00:00:10,220 --> 00:00:14,660
And for this we could structure our code here differently
6
00:00:14,660 --> 00:00:16,590
and add more styling,
7
00:00:16,590 --> 00:00:20,320
but ultimately I simply want to create a new component here
8
00:00:20,320 --> 00:00:23,210
and add component specific styling.
9
00:00:23,210 --> 00:00:24,690
So that's what we'll do.
10
00:00:24,690 --> 00:00:28,000
In the components folder I'll add another subfolder
11
00:00:28,000 --> 00:00:30,630
next to layout, and I'll name it meetups.
12
00:00:30,630 --> 00:00:34,030
And this holds all my meetup specific code.
13
00:00:34,030 --> 00:00:37,600
And in there I'll add a MeetupItem.js file,
14
00:00:37,600 --> 00:00:41,180
and a MeetupList.js file
15
00:00:41,180 --> 00:00:43,550
because I want to outsource both the list
16
00:00:43,550 --> 00:00:46,040
as well as the individual list items
17
00:00:46,040 --> 00:00:48,010
into components.
18
00:00:48,010 --> 00:00:51,260
Because, as mentioned earlier, it is a good practice to
19
00:00:51,260 --> 00:00:54,700
split your components and your application as a whole
20
00:00:54,700 --> 00:00:57,940
into small, reusable pieces.
21
00:00:57,940 --> 00:01:00,350
Now let's start with the MeetupItem.
22
00:01:00,350 --> 00:01:04,349
In that file, we create our MeetupItem function of course,
23
00:01:04,349 --> 00:01:05,700
as we did before,
24
00:01:05,700 --> 00:01:08,909
and we export that function.
25
00:01:08,909 --> 00:01:12,720
Then in here, we return a list item.
26
00:01:12,720 --> 00:01:16,210
And then in that list item, I want to have a div,
27
00:01:16,210 --> 00:01:20,130
in which I render the image and set the source to something
28
00:01:20,130 --> 00:01:22,620
and the alt text to something,
29
00:01:22,620 --> 00:01:25,570
and then that's a self-closing element,
30
00:01:25,570 --> 00:01:30,040
and below that div I have another div with the content,
31
00:01:30,040 --> 00:01:34,220
where I have a h3 tag with the title,
32
00:01:34,220 --> 00:01:38,410
an address tag, which is a default html tag,
33
00:01:38,410 --> 00:01:41,870
where I output the address later,
34
00:01:41,870 --> 00:01:45,600
and then a paragraph with the description.
35
00:01:45,600 --> 00:01:48,330
And all this hard coded text will of course
36
00:01:48,330 --> 00:01:51,740
soon be replaced with dynamic data.
37
00:01:51,740 --> 00:01:54,240
And then below that we can add another div
38
00:01:54,240 --> 00:01:59,240
with a button, where we say to Favorites,
39
00:01:59,370 --> 00:02:04,180
so that this adds the item to our Favorites later.
40
00:02:04,180 --> 00:02:07,710
That's the general structure I want to have here.
41
00:02:07,710 --> 00:02:10,850
Now as mentioned, title, address, and description,
42
00:02:10,850 --> 00:02:14,340
and also the data for the image, should be dynamic.
43
00:02:14,340 --> 00:02:16,820
I don't want to hard code it here.
44
00:02:16,820 --> 00:02:20,680
Instead, it should be passed in from outside,
45
00:02:20,680 --> 00:02:23,270
from the so-called parent component,
46
00:02:23,270 --> 00:02:26,020
so the component where we use this component
47
00:02:26,020 --> 00:02:28,180
in its jsx code.
48
00:02:28,180 --> 00:02:30,825
And we learned how we can make that happen,
49
00:02:30,825 --> 00:02:34,720
we can accept props here and use props.
50
00:02:34,720 --> 00:02:37,810
And then for example, for the image source,
51
00:02:37,810 --> 00:02:41,030
we could set this to props.image,
52
00:02:41,030 --> 00:02:44,050
expecting a image prop on the MeetupItem,
53
00:02:44,050 --> 00:02:49,050
which holds that URL that should be set as a source here.
54
00:02:49,170 --> 00:02:53,000
And the same for the alt text that could be our title.
55
00:02:53,000 --> 00:02:55,170
The title can also be used down there,
56
00:02:55,170 --> 00:02:58,530
so that'd be output props.title here.
57
00:02:58,530 --> 00:03:02,040
And for the address, it's props.address.
58
00:03:02,040 --> 00:03:06,083
For the description, it's props.description.
59
00:03:07,350 --> 00:03:11,070
And now, all of a sudden this component is reusable
60
00:03:11,070 --> 00:03:12,223
and dynamic.
61
00:03:13,480 --> 00:03:15,860
Some styling would also be nice, and for that,
62
00:03:15,860 --> 00:03:19,290
again attach, you find css files here,
63
00:03:19,290 --> 00:03:21,830
the meetupitem.module css
64
00:03:21,830 --> 00:03:25,140
and the meetuplist.module css files,
65
00:03:25,140 --> 00:03:30,140
which you can copy in next to these JavaScript files,
66
00:03:30,300 --> 00:03:33,544
and then in meetupitem.js we want to import
67
00:03:33,544 --> 00:03:38,544
classes from./meetupitem.module.css
68
00:03:40,340 --> 00:03:44,660
and assign a couple of classes in that JavaScript file.
69
00:03:44,660 --> 00:03:46,350
On the list item for example,
70
00:03:46,350 --> 00:03:51,350
we'll add the item class like this on this div,
71
00:03:51,780 --> 00:03:53,300
which is wrapped around the image,
72
00:03:53,300 --> 00:03:57,680
we'll add the image class like this on the div
73
00:03:57,680 --> 00:04:01,370
which is wrapped around the title and description and so on,
74
00:04:01,370 --> 00:04:03,454
we'll add the content class,
75
00:04:03,454 --> 00:04:07,363
and then down there, for the button,
76
00:04:08,630 --> 00:04:12,263
I'll add a class of actions, like this.
77
00:04:13,870 --> 00:04:17,060
Now that's not all. I also want to work on that MeetupList
78
00:04:17,060 --> 00:04:18,970
component already.
79
00:04:18,970 --> 00:04:21,911
So here we can again create another component,
80
00:04:21,911 --> 00:04:26,730
MeetupList, and export that as a default.
81
00:04:26,730 --> 00:04:29,640
Also accept props here, because I expect
82
00:04:29,640 --> 00:04:32,900
to get that list data from outside as well,
83
00:04:32,900 --> 00:04:35,070
and I'm expecting this because I'm the one
84
00:04:35,070 --> 00:04:36,530
building this app.
85
00:04:36,530 --> 00:04:39,620
We could also write the code for fetching meetups
86
00:04:39,620 --> 00:04:43,530
in this component, but I instead want to make this component
87
00:04:43,530 --> 00:04:47,870
reusable and not care about the data source in here,
88
00:04:47,870 --> 00:04:50,500
but instead just expect that I get meetups
89
00:04:50,500 --> 00:04:51,830
through some prop,
90
00:04:51,830 --> 00:04:55,190
and then it's a component which uses the MeetupList
91
00:04:55,190 --> 00:04:58,990
component that has to worry about getting the meetups.
92
00:04:58,990 --> 00:05:00,610
And I'm setting it up like this
93
00:05:00,610 --> 00:05:03,800
because I plan on using the MeetupList component
94
00:05:03,800 --> 00:05:05,970
in the AllMeetups component,
95
00:05:05,970 --> 00:05:08,780
and also in the Favorites component later.
96
00:05:08,780 --> 00:05:11,694
And there we'll have different data sources,
97
00:05:11,694 --> 00:05:14,640
but the same way of displaying the data.
98
00:05:14,640 --> 00:05:16,600
And that's what we can make work
99
00:05:16,600 --> 00:05:19,883
by adding a separate reusable component.
100
00:05:21,480 --> 00:05:25,410
In here I also already wanna import classes
101
00:05:25,410 --> 00:05:30,020
from ./MeetupList.module.css,
102
00:05:30,020 --> 00:05:32,432
and return an unordered list here,
103
00:05:32,432 --> 00:05:36,720
which receives a class name of classes.list
104
00:05:37,590 --> 00:05:42,590
which is the only provided css class for this component.
105
00:05:44,050 --> 00:05:46,650
And inside of the unordered list here,
106
00:05:46,650 --> 00:05:49,832
I now wanna output my MeetupItems
107
00:05:49,832 --> 00:05:53,000
in the same way we did it in AllMeetups,
108
00:05:53,000 --> 00:05:56,170
by mapping an array of objects
109
00:05:56,170 --> 00:05:59,070
into an array of jsx elements.
110
00:05:59,070 --> 00:06:04,070
Just that the jsx elements will now be the list items.
111
00:06:05,160 --> 00:06:08,630
And for this here we again add a dynamic expression
112
00:06:08,630 --> 00:06:09,952
with curly braces,
113
00:06:09,952 --> 00:06:13,290
and we can expect that on our props here
114
00:06:13,290 --> 00:06:17,094
in MeetupList, we get, let's say, a meetups prop,
115
00:06:17,094 --> 00:06:20,250
the name is up to you, because it's your component,
116
00:06:20,250 --> 00:06:22,830
this could all be named items,
117
00:06:22,830 --> 00:06:24,990
but here I'll go with meetups.
118
00:06:24,990 --> 00:06:29,173
And then I'll map every meetup into another object.
119
00:06:30,040 --> 00:06:32,750
Into a jsx element, to be precise.
120
00:06:32,750 --> 00:06:35,700
So therefore, using the arrow function
121
00:06:35,700 --> 00:06:37,750
shorthand subtext here,
122
00:06:37,750 --> 00:06:41,370
I'll transform every meetup into a MeetupItem.
123
00:06:43,750 --> 00:06:46,140
And for this, you need to add this import.
124
00:06:46,140 --> 00:06:49,650
It was automatically added for me here by the IDE.
125
00:06:49,650 --> 00:06:52,760
If that does not work for you, just add it manually,
126
00:06:52,760 --> 00:06:56,423
and import MeetupItem from the MeetupItem file.
127
00:06:57,730 --> 00:07:00,570
Now we render one MeetupItem per object
128
00:07:00,570 --> 00:07:02,350
in the meetups array,
129
00:07:02,350 --> 00:07:04,500
and that now needs to be configured.
130
00:07:04,500 --> 00:07:07,470
It needs this key prop, this special prop,
131
00:07:07,470 --> 00:07:11,650
React expects, one of the very few special props
132
00:07:11,650 --> 00:07:14,930
that are built into React, and that can be used
133
00:07:14,930 --> 00:07:18,130
on any component, including your own components,
134
00:07:18,130 --> 00:07:20,820
without you writing any special code for it
135
00:07:20,820 --> 00:07:22,870
inside of your components.
136
00:07:22,870 --> 00:07:25,530
So you can just add that anywhere.
137
00:07:25,530 --> 00:07:27,783
And we set that equal to Meetup.id.
138
00:07:28,640 --> 00:07:32,830
Then, in my own component, I'll actually pass
139
00:07:32,830 --> 00:07:36,450
in the id as well, as a id prop,
140
00:07:36,450 --> 00:07:39,920
we will use that later for the Favorite feature.
141
00:07:39,920 --> 00:07:44,626
I'll pass in the image prop with meetup.image,
142
00:07:44,626 --> 00:07:48,280
let me reformat this to make it a bit more readable.
143
00:07:48,280 --> 00:07:52,273
At the title prop and point at meetup.title,
144
00:07:53,210 --> 00:07:55,643
and also at address and description.
145
00:07:56,920 --> 00:08:00,500
So meetup.address, and description is equal
146
00:08:00,500 --> 00:08:02,893
to meetup.description.
147
00:08:03,920 --> 00:08:06,750
Now alternatively, we could've also just passed
148
00:08:06,750 --> 00:08:09,810
in a meetup prop, or any other name,
149
00:08:09,810 --> 00:08:12,600
and just passed in the meetup as a whole.
150
00:08:12,600 --> 00:08:14,890
Then we would have to de-structure it
151
00:08:14,890 --> 00:08:17,350
inside of the MeetupItem component.
152
00:08:17,350 --> 00:08:19,470
It's up to you which approach you prefer,
153
00:08:19,470 --> 00:08:22,283
here I'm passing in individual props.
154
00:08:23,630 --> 00:08:25,040
With all of that done, though,
155
00:08:25,040 --> 00:08:26,910
we can go back to AllMeetups
156
00:08:26,910 --> 00:08:29,650
and now use the meetup list component
157
00:08:29,650 --> 00:08:32,159
instead of the unordered list.
158
00:08:32,159 --> 00:08:36,629
So we go up and we import.
159
00:08:36,629 --> 00:08:40,900
MeetupList from, going up one level,
160
00:08:40,900 --> 00:08:42,669
out of the pages folder,
161
00:08:42,669 --> 00:08:44,400
into the components folder,
162
00:08:44,400 --> 00:08:46,000
into the meetups folder,
163
00:08:46,000 --> 00:08:46,833
to MeetupList,
164
00:08:48,920 --> 00:08:52,433
and then just output MeetupList like this,
165
00:08:54,570 --> 00:08:58,580
and very important, provide the meetups' prop.
166
00:08:58,580 --> 00:09:01,010
Because we're expecting that prop inside
167
00:09:01,010 --> 00:09:03,293
of the MeetupList component, here.
168
00:09:05,020 --> 00:09:07,200
So set up the meetups prop here,
169
00:09:07,200 --> 00:09:09,610
and pass in the dummy data array
170
00:09:09,610 --> 00:09:11,420
as a value.
171
00:09:11,420 --> 00:09:14,510
With all of that done, if you save all the files,
172
00:09:14,510 --> 00:09:16,343
you should see something like this.
173
00:09:17,590 --> 00:09:19,920
Now this is not the final look,
174
00:09:19,920 --> 00:09:21,840
we'll continue tweaking this,
175
00:09:21,840 --> 00:09:25,240
but it shows that our content is being rendered.
176
00:09:25,240 --> 00:09:27,920
And that's not too bad.
177
00:09:27,920 --> 00:09:31,810
But now it would be nice to kind of restrict the width,
178
00:09:31,810 --> 00:09:33,570
which we use on the screen,
179
00:09:33,570 --> 00:09:36,440
and it would also be nice if the individual meetups
180
00:09:36,440 --> 00:09:40,730
would look like cards, with a nice drop shadow,
181
00:09:40,730 --> 00:09:44,230
maybe rounded corners, something like that.
182
00:09:44,230 --> 00:09:46,030
That's what we're going to add next.
14266
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.