Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:01,040 --> 00:00:09,770
Now, let's start making our application resemble more closely to our actual final monstrous Rolodex
2
00:00:09,770 --> 00:00:15,710
application so we know that we need to display a list of monsters.
3
00:00:16,129 --> 00:00:23,780
So instead of the string, hello, Iowa, I'm going to make a new property called Monsters, and I'm
4
00:00:23,780 --> 00:00:28,360
going to make it an array of objects that have a name on it.
5
00:00:29,180 --> 00:00:30,520
That's a string value.
6
00:00:30,860 --> 00:00:38,960
So our first monster will be Frankenstein, our second monster will be Dracula, and our third monster
7
00:00:38,960 --> 00:00:40,940
will be a zombie.
8
00:00:42,190 --> 00:00:42,820
So.
9
00:00:43,600 --> 00:00:44,170
Here.
10
00:00:45,360 --> 00:00:53,260
I want to render, let's say, just a bunch of H ones with the actual names of these monsters, right.
11
00:00:53,490 --> 00:00:57,780
So how I would go about doing that is I'm going to go right to this because we don't need this anymore.
12
00:00:58,800 --> 00:01:03,660
And we write our curly braces because we've got to render some JavaScript, right?
13
00:01:03,670 --> 00:01:08,710
So now between these curly braces, we can really render any JavaScript that we want.
14
00:01:09,150 --> 00:01:19,260
So I am going to call this Stotz state dot monsters dot map because MAP returns us the return of whatever
15
00:01:19,260 --> 00:01:20,880
function we pass to.
16
00:01:20,880 --> 00:01:26,390
It iterated over every element in this array.
17
00:01:26,400 --> 00:01:26,720
Right.
18
00:01:26,850 --> 00:01:32,970
So when I say iterate, what I mean is that this function that I write here, whatever this returns.
19
00:01:34,650 --> 00:01:44,040
It's going to return in the place of every element in this array, so I'm going to call map on this
20
00:01:44,430 --> 00:01:54,990
monster's array and map takes a function where the first argument is going to be the actual element
21
00:01:55,140 --> 00:01:57,870
that this function is going to get called on.
22
00:01:57,900 --> 00:01:58,190
Right.
23
00:01:58,210 --> 00:02:05,430
So it's going to call the function we pass in on it on Frankenstein and then on Dracula and then on
24
00:02:05,430 --> 00:02:06,060
the zombie.
25
00:02:06,090 --> 00:02:06,310
Right.
26
00:02:06,330 --> 00:02:08,380
It's going to call it on each object.
27
00:02:08,759 --> 00:02:13,830
Now, what that function returns will be what gets returned out of this map.
28
00:02:13,830 --> 00:02:16,770
Usually it's a new array, right, when you call map.
29
00:02:16,770 --> 00:02:24,000
But React is smart enough to know that if we end up rendering out a bunch of HTML blocks right in an
30
00:02:24,000 --> 00:02:27,610
array, then it will just display those elements.
31
00:02:27,660 --> 00:02:29,080
So let's take a look.
32
00:02:29,820 --> 00:02:31,770
So our first element, right?
33
00:02:31,830 --> 00:02:33,560
Our first argument is monster.
34
00:02:34,050 --> 00:02:37,530
So I'm going to return a new one.
35
00:02:39,960 --> 00:02:40,350
But.
36
00:02:41,350 --> 00:02:42,000
Each one.
37
00:02:43,260 --> 00:02:49,500
Where I'm going to, again, call the curly braces, because this is a new return block, right, of
38
00:02:49,710 --> 00:02:51,240
TML, just like here, right?
39
00:02:51,570 --> 00:02:53,090
It's going to need new curly braces.
40
00:02:53,100 --> 00:02:55,850
And inside I'm gonna call monster name.
41
00:02:58,440 --> 00:02:59,760
Now, what we should see.
42
00:03:01,070 --> 00:03:03,390
Is the name of each of our monsters, right?
43
00:03:03,440 --> 00:03:11,240
We see that now if we open up our console, we'll see this warning that says each child in a list should
44
00:03:11,240 --> 00:03:12,730
have a unique Kiprop.
45
00:03:13,070 --> 00:03:18,970
So it's asking us to add a unique key to every child that gets return out of this map.
46
00:03:18,980 --> 00:03:19,350
Right.
47
00:03:19,640 --> 00:03:25,460
We got to provide something that is unique completely to this list of elements.
48
00:03:25,460 --> 00:03:25,740
Right.
49
00:03:26,240 --> 00:03:33,050
So let's just make a value of ID and just call it something like this.
50
00:03:33,440 --> 00:03:33,860
Right.
51
00:03:33,860 --> 00:03:35,940
On any random unique string.
52
00:03:35,960 --> 00:03:36,800
Well, work.
53
00:03:41,900 --> 00:03:45,440
The reason why we want a unique key.
54
00:03:46,880 --> 00:03:50,240
Is because React needs to know.
55
00:03:51,640 --> 00:04:02,020
What element it needs to update if one of these elements in our array has a value that changes right
56
00:04:02,260 --> 00:04:08,890
now, let's say, for example, the user does something and it changes the name of our first.
57
00:04:09,920 --> 00:04:17,630
Monster from Frankenstein to Banshee, for example, right, like let's say it does it in the code somewhere,
58
00:04:17,630 --> 00:04:20,250
like the same way that we saw when we called sets state earlier.
59
00:04:20,660 --> 00:04:27,800
Well, REACT is smart enough to know that it only needs to update that first one.
60
00:04:28,070 --> 00:04:28,460
Right.
61
00:04:29,120 --> 00:04:32,210
To change it to that new the new prop..
62
00:04:32,690 --> 00:04:41,030
It doesn't need to re render all of these and the key helps react, understand it helps it know which
63
00:04:41,030 --> 00:04:43,070
element is the one that's been updated.
64
00:04:43,070 --> 00:04:43,310
Right.
65
00:04:43,310 --> 00:04:50,750
Which is attached to which element so that it knows that it doesn't have to render everything.
66
00:04:51,230 --> 00:04:59,300
You can see how if this list was way bigger, it would be really performant heavy to render all everything.
67
00:04:59,660 --> 00:05:01,760
And that's what makes react so great.
68
00:05:02,180 --> 00:05:03,380
It's that it's smart.
69
00:05:03,770 --> 00:05:12,830
It knows that if only one element in a list of a thousand elements changes, it only needs to re render
70
00:05:12,860 --> 00:05:17,220
the part of the HTML that matters, not the whole thing.
71
00:05:17,990 --> 00:05:24,590
So now that we have our list, we actually want to make this look closer to the final.
72
00:05:24,920 --> 00:05:29,930
So right now, these are just placeholders for us to understand a little bit more of what it's like
73
00:05:29,930 --> 00:05:35,210
to write, react right where, iterating over an array and creating new elements.
74
00:05:35,480 --> 00:05:39,320
But let's actually dive a little deeper into it.
6592
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.