Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:01,483 --> 00:00:03,300
So let's now outsource
2
00:00:03,300 --> 00:00:07,203
these concept items here, into a separate component.
3
00:00:08,751 --> 00:00:10,020
And for that of course,
4
00:00:10,020 --> 00:00:13,740
I wanna outsource this list item code here in the end,
5
00:00:13,740 --> 00:00:15,450
into a separate component.
6
00:00:15,450 --> 00:00:17,070
For that, in the components folder,
7
00:00:17,070 --> 00:00:20,640
we can add another sub folder called concept,
8
00:00:20,640 --> 00:00:23,509
though of course this name as always, is up to you.
9
00:00:23,509 --> 00:00:28,080
And then in there, create a concept.js file,
10
00:00:28,080 --> 00:00:30,570
where I also have my concept function
11
00:00:30,570 --> 00:00:32,580
for this concept component,
12
00:00:32,580 --> 00:00:34,770
which of course must be exported,
13
00:00:34,770 --> 00:00:36,993
to make it available outside of this file.
14
00:00:38,430 --> 00:00:43,430
And then here, I want to return this list item, JSX code.
15
00:00:44,550 --> 00:00:47,220
So I can cut it from here, from app.js,
16
00:00:47,220 --> 00:00:49,533
and move it here into concept.js.
17
00:00:50,970 --> 00:00:54,040
Now, one very important note here,
18
00:00:54,040 --> 00:00:57,008
in theory, we could now create
19
00:00:57,008 --> 00:01:00,120
three different concept components,
20
00:01:00,120 --> 00:01:03,299
one for every core concept that we're outputting here.
21
00:01:03,299 --> 00:01:05,400
But if we would do that,
22
00:01:05,400 --> 00:01:09,120
we would still be duplicating, and replicating code.
23
00:01:09,120 --> 00:01:12,210
And if we ever wanted to delete the paragraph,
24
00:01:12,210 --> 00:01:14,100
we still would have to do that
25
00:01:14,100 --> 00:01:16,143
in three different components.
26
00:01:17,130 --> 00:01:20,580
That's why I'm not building three different components here.
27
00:01:20,580 --> 00:01:23,790
But instead, one reusable component,
28
00:01:23,790 --> 00:01:26,460
which must be configurable, though.
29
00:01:26,460 --> 00:01:28,110
It must be configurable,
30
00:01:28,110 --> 00:01:30,540
so that one and the same component
31
00:01:30,540 --> 00:01:32,940
can output different data.
32
00:01:32,940 --> 00:01:36,090
Data that's always output in the same way,
33
00:01:36,090 --> 00:01:39,030
so that it always has the same shape in the end.
34
00:01:39,030 --> 00:01:41,499
But the different data pieces,
35
00:01:41,499 --> 00:01:44,100
the image, the title, the description,
36
00:01:44,100 --> 00:01:48,930
the values stored under those keys, that will differ.
37
00:01:48,930 --> 00:01:51,870
And that's the idea here with this function component.
38
00:01:51,870 --> 00:01:52,703
So therefore,
39
00:01:52,703 --> 00:01:55,787
it must be configurable, in order to be reusable.
40
00:01:55,787 --> 00:01:59,430
And how do we make it configurable?
41
00:01:59,430 --> 00:02:01,113
With help of props.
42
00:02:02,250 --> 00:02:06,180
So here we can, and should, accept this props argument,
43
00:02:06,180 --> 00:02:08,160
this props parameter,
44
00:02:08,160 --> 00:02:11,760
which will be created and managed automatically by React,
45
00:02:11,760 --> 00:02:12,960
and which will be passed
46
00:02:12,960 --> 00:02:15,363
into this component function by React.
47
00:02:16,800 --> 00:02:19,830
And then with that, here we can, for example,
48
00:02:19,830 --> 00:02:24,830
output props.image, and here props.title.
49
00:02:25,890 --> 00:02:28,560
And here it's also props.title.
50
00:02:28,560 --> 00:02:30,720
And the same as true here for description,
51
00:02:30,720 --> 00:02:32,733
it's props.description.
52
00:02:33,930 --> 00:02:37,260
And with that, we made this component configurable,
53
00:02:37,260 --> 00:02:40,650
and it does now accept an image, a title,
54
00:02:40,650 --> 00:02:42,360
and a description key,
55
00:02:42,360 --> 00:02:44,070
which can and should be set
56
00:02:44,070 --> 00:02:47,043
when that component is being used in JSX code.
57
00:02:48,300 --> 00:02:50,516
Therefore now back in app.js,
58
00:02:50,516 --> 00:02:53,880
we can use this concept component here.
59
00:02:53,880 --> 00:02:58,083
And for it to be usable here, we also must import it.
60
00:02:59,010 --> 00:03:01,710
So here we should import concept
61
00:03:01,710 --> 00:03:06,710
from ./Components/Concept/Concept.
62
00:03:09,360 --> 00:03:12,810
And with that import here added, we can go down,
63
00:03:12,810 --> 00:03:14,400
use the concept component like this,
64
00:03:14,400 --> 00:03:16,680
as a self-closing component here,
65
00:03:16,680 --> 00:03:18,510
because I'm not passing anything
66
00:03:18,510 --> 00:03:21,480
between its opening and closing tabs.
67
00:03:21,480 --> 00:03:26,480
And then here, we can set the image prop, like this,
68
00:03:28,110 --> 00:03:32,220
because in concept, I'm extracting an image prop
69
00:03:32,220 --> 00:03:33,900
So I'm looking for this key,
70
00:03:33,900 --> 00:03:37,230
hence we should provide it here, on this component.
71
00:03:37,230 --> 00:03:41,237
And set these to concepts(0).image.
72
00:03:44,910 --> 00:03:48,780
So we're still accessing that concepts data from this array,
73
00:03:48,780 --> 00:03:52,620
but we're now passing it to our own custom component.
74
00:03:52,620 --> 00:03:53,453
And of course,
75
00:03:53,453 --> 00:03:55,290
we're now going to do the same for the title.
76
00:03:55,290 --> 00:03:59,520
Here, we should access concepts(0).title.
77
00:03:59,520 --> 00:04:02,880
And last but not least, we also wanna do that
78
00:04:02,880 --> 00:04:04,500
for the description of course,
79
00:04:04,500 --> 00:04:07,650
and pass concepts(0).description,
80
00:04:07,650 --> 00:04:10,203
as a value for the description prop.
81
00:04:11,940 --> 00:04:15,120
With that, if I formatted this, the code looks like this.
82
00:04:15,120 --> 00:04:18,709
And now we can easily replace those list items here,
83
00:04:18,709 --> 00:04:21,978
with our own custom component,
84
00:04:21,978 --> 00:04:25,440
and pass the correct data to the props.
85
00:04:25,440 --> 00:04:29,160
So here for concepts(1), on that second item,
86
00:04:29,160 --> 00:04:32,130
and on the third item for concepts(2),
87
00:04:32,130 --> 00:04:34,934
so for the third concepts item.
88
00:04:34,934 --> 00:04:38,460
And with that, we now got this reusable component,
89
00:04:38,460 --> 00:04:40,350
and we are reusing it,
90
00:04:40,350 --> 00:04:44,040
and we are configuring it, with help of props.
91
00:04:44,040 --> 00:04:48,212
And the HTML structure, is now only defined once,
92
00:04:48,212 --> 00:04:50,259
inside of this component,
93
00:04:50,259 --> 00:04:52,920
but it can now easily be reused,
94
00:04:52,920 --> 00:04:55,530
thanks to our custom component.
95
00:04:55,530 --> 00:04:58,950
And I make sure that here I'm accessing concepts(2),
96
00:04:58,950 --> 00:05:01,800
not concepts(3), which would be wrong.
97
00:05:01,800 --> 00:05:03,768
And I saved this again.
98
00:05:03,768 --> 00:05:06,690
I've now got the same website as before,
99
00:05:06,690 --> 00:05:09,360
with those key concepts items,
100
00:05:09,360 --> 00:05:12,780
but now we're building it with help of custom components,
101
00:05:12,780 --> 00:05:15,345
custom reusable components.
102
00:05:15,345 --> 00:05:18,840
And therefore, all three tasks that I gave you
103
00:05:18,840 --> 00:05:21,933
at the beginning of the section, are now solved.
7979
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.