Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:01,110 --> 00:00:08,290
Now, before we begin, I want to peel back the curtain a little bit on what it is that Create React
2
00:00:08,290 --> 00:00:12,450
app was doing for us because create racked up sets up a lot for us.
3
00:00:12,450 --> 00:00:16,560
And when we were writing our code, it kind of seemed like there was a lot of magic happening.
4
00:00:17,130 --> 00:00:21,930
But I'm going to show you what react and react, Dom, as libraries do.
5
00:00:21,930 --> 00:00:26,900
And I'm just going to use pure vanilla JavaScript and some HTML.
6
00:00:27,360 --> 00:00:29,310
It's actually incredibly easy.
7
00:00:29,610 --> 00:00:35,160
And the first thing that I'm going to do is I'm going to make a new folder called Purulia.
8
00:00:36,490 --> 00:00:46,000
And inside of pure react, I am going to make a sauce folder and then inside of our sauce folder, I'm
9
00:00:46,000 --> 00:00:49,230
going to make index dot HTML5.
10
00:00:50,610 --> 00:00:51,870
And then we're going to open it up.
11
00:00:54,960 --> 00:01:01,290
Now, inside of our index, that HTML file, I'm going to just generate our basic.
12
00:01:02,220 --> 00:01:05,850
HTML, right, our basic base demo.
13
00:01:07,080 --> 00:01:16,890
And then I'm going to in the body add in that div that we first saw inside of our monster's Rolodex
14
00:01:17,310 --> 00:01:19,290
with the idea of root.
15
00:01:20,280 --> 00:01:31,410
Now, if you remember, what we do in our index dodgiest file is we replace that root div with the actual
16
00:01:31,410 --> 00:01:32,960
content of our application.
17
00:01:33,390 --> 00:01:34,710
So that's what we need to do as well.
18
00:01:34,740 --> 00:01:35,670
We need that same thing.
19
00:01:35,670 --> 00:01:35,990
Right.
20
00:01:36,390 --> 00:01:41,040
And then we're going to include the two packages, react and react, Dom.
21
00:01:42,600 --> 00:01:49,130
In order to do that, I'm just going to add a script tag where the source goes to the Riak project.
22
00:01:49,470 --> 00:01:55,770
So this is something called Unpackaged, which lets us very easily bring in the Riak library.
23
00:01:56,940 --> 00:02:01,830
Just like that, and then we're going to do the same thing with react on.
24
00:02:07,590 --> 00:02:13,950
Our REAC project has both these libraries, so why are there to write?
25
00:02:14,280 --> 00:02:17,090
Well, React is kind of just the API, right?
26
00:02:17,100 --> 00:02:23,130
But then the thing that actually renders out to the dorm is what react on is the reason for this is
27
00:02:23,130 --> 00:02:26,450
because react is a great kind of engine.
28
00:02:26,580 --> 00:02:26,990
Right.
29
00:02:27,360 --> 00:02:30,840
But you could have many different views that run on the same engine.
30
00:02:31,290 --> 00:02:36,450
So react is for the web and you might have to react native reacting if it is actually exactly what it
31
00:02:36,450 --> 00:02:36,600
is.
32
00:02:36,600 --> 00:02:39,830
It's for native Android and iOS.
33
00:02:40,200 --> 00:02:46,770
So while it uses the same react engine, it uses a different package other than react dom to render
34
00:02:46,770 --> 00:02:49,890
its Android and iOS views.
35
00:02:50,580 --> 00:02:55,320
So that's why it's such a great package, because you can even find ones like really 60 if you want
36
00:02:55,320 --> 00:02:57,660
to build 3-D stuff.
37
00:02:57,900 --> 00:02:59,880
Right, like virtual reality stuff.
38
00:03:01,050 --> 00:03:07,200
But that's all we're doing, which is pulling in these two packages now to show that it actually removes
39
00:03:07,200 --> 00:03:09,690
what's inside of this root div.
40
00:03:09,690 --> 00:03:15,240
When we actually render in our reachout, I'm just going to put in here react rendered first.
41
00:03:16,390 --> 00:03:20,470
So let's open up our index, that HTML in the browser.
42
00:03:21,750 --> 00:03:26,280
And now we'll see that react is not rendered right, because we haven't actually done that call where
43
00:03:26,280 --> 00:03:32,190
we replace the content inside of this div with our application and we haven't built the application
44
00:03:32,190 --> 00:03:32,430
yet.
45
00:03:32,820 --> 00:03:39,390
But first, if we open up our dev tools, we can actually see now because we pulled in both those packages,
46
00:03:39,600 --> 00:03:43,080
we have access to both react and react, Dom.
47
00:03:43,200 --> 00:03:43,590
Right.
48
00:03:44,970 --> 00:03:51,660
These are the objects that the two packages provide into our global JavaScript namespace once we brought
49
00:03:51,660 --> 00:03:52,630
those packages in.
50
00:03:52,680 --> 00:03:58,530
And this is pretty much the same thing that we do when we import in react and react, Dom, into our
51
00:03:58,530 --> 00:03:59,010
files.
52
00:04:00,200 --> 00:04:04,430
It just gives us access to these two things right now.
53
00:04:05,890 --> 00:04:11,260
I'm going to actually add my own script tag and inside we're going to start writing our own JavaScript
54
00:04:11,590 --> 00:04:13,660
to see what it is that these libraries do for us.
55
00:04:14,380 --> 00:04:19,899
So first, I'm going to write a functional component called app the same way we were writing them before.
56
00:04:20,200 --> 00:04:27,310
Except this time, what I'm going to return is react, John, create elements now, create element is
57
00:04:27,310 --> 00:04:36,070
a function on Riak that builds out those elements that we saw when we wrote our return right inside
58
00:04:36,070 --> 00:04:37,860
of like, let's say, our Kahless component.
59
00:04:38,110 --> 00:04:38,440
Right.
60
00:04:38,560 --> 00:04:40,900
It just we return from this function.
61
00:04:40,930 --> 00:04:45,130
This HTML markup will create element is actually what it's doing.
62
00:04:45,490 --> 00:04:48,550
But instead of sex, this is vanilla, right?
63
00:04:48,580 --> 00:04:54,320
So what we got to do is we write in here that we want to make a div right.
64
00:04:54,340 --> 00:04:59,620
You can put any other HTML tag or whatever that you're looking for, but I want to do so.
65
00:04:59,620 --> 00:05:07,330
I put div and then the second argument is an object of any attributes that I want to add to my div.
66
00:05:07,360 --> 00:05:11,800
So if I wanted to add a class or an ID right, I would put them in here.
67
00:05:11,800 --> 00:05:12,100
Right.
68
00:05:12,610 --> 00:05:19,630
So like if I wanted a class right then I would put like, you know, card list the same way I did before.
69
00:05:19,630 --> 00:05:19,950
Right.
70
00:05:20,170 --> 00:05:22,630
But I don't want one so I can keep it empty.
71
00:05:23,200 --> 00:05:29,040
And then the third and last argument is any children we want to nest inside of our div, right?
72
00:05:29,650 --> 00:05:34,360
So I want to put in react create element again.
73
00:05:34,480 --> 00:05:34,840
Right.
74
00:05:35,230 --> 00:05:38,040
And I'm going to put on an H1 again.
75
00:05:38,050 --> 00:05:39,280
I don't want any attributes.
76
00:05:39,880 --> 00:05:46,090
And inside of our H1, I'm going to put the text react is rendered right.
77
00:05:47,800 --> 00:05:48,580
And now.
78
00:05:49,770 --> 00:05:51,330
We have our functional component.
79
00:05:52,640 --> 00:05:59,300
And I'm going to call react, dom render, I'm going to put a react crit element again, right?
80
00:06:00,410 --> 00:06:01,700
And I'm going to put on our app.
81
00:06:02,690 --> 00:06:07,970
I'm not actually going to give it these two because these are actually optional, right, these last
82
00:06:07,970 --> 00:06:10,680
two arguments are completely optional.
83
00:06:10,820 --> 00:06:11,750
I don't want attributes.
84
00:06:11,750 --> 00:06:12,490
I don't want children.
85
00:06:13,040 --> 00:06:13,400
Right.
86
00:06:13,820 --> 00:06:18,930
And then you remember with our render, we got to target that element that we want.
87
00:06:19,130 --> 00:06:22,400
So get element by ID of route.
88
00:06:24,180 --> 00:06:25,260
And just like that.
89
00:06:26,370 --> 00:06:27,270
If we refresh.
90
00:06:29,410 --> 00:06:30,200
Reactors rendered.
91
00:06:30,400 --> 00:06:30,760
Right.
92
00:06:31,130 --> 00:06:33,610
That's all we were doing here.
93
00:06:34,580 --> 00:06:40,180
Except with gas, but now we're just doing it with vanilla JavaScript, right, that's all it's doing.
94
00:06:40,190 --> 00:06:41,710
React, Dom, render right.
95
00:06:41,720 --> 00:06:43,880
We're creating that our application.
96
00:06:44,150 --> 00:06:44,530
Right.
97
00:06:45,080 --> 00:06:49,040
And just like that, we that's all the react library does for us.
98
00:06:49,040 --> 00:06:55,820
It just helps us create these HTML elements using functions or classes right now.
99
00:06:56,150 --> 00:06:58,940
Let's actually take this a step further now.
100
00:06:58,940 --> 00:07:03,230
Let's say I wanted to make a contact person.
101
00:07:03,470 --> 00:07:03,890
Right.
102
00:07:05,360 --> 00:07:08,420
And CONSED person is the same thing.
103
00:07:08,870 --> 00:07:17,000
It just react to create element and inside as a div right now attributes.
104
00:07:18,110 --> 00:07:25,430
And instead, what I want to render is an array, so if we want to multiple elements, right, we want
105
00:07:25,430 --> 00:07:28,300
a multiple children inside of this dif, we would just use an array.
106
00:07:28,610 --> 00:07:32,960
And inside I would do react create element H1.
107
00:07:35,140 --> 00:07:37,540
And then an empty object.
108
00:07:38,460 --> 00:07:40,740
And I'm going to put EOWA.
109
00:07:42,140 --> 00:07:47,930
And then I'm going to make another one, except it's going to be a PAETEC and it's going to say developer.
110
00:07:49,630 --> 00:07:50,440
And now.
111
00:07:51,680 --> 00:07:59,510
Instead of just rendering in our application that each one of reracked is rendered right, I'm also
112
00:07:59,510 --> 00:08:00,980
going to render in.
113
00:08:02,730 --> 00:08:04,140
Multiple person.
114
00:08:07,260 --> 00:08:12,660
I'm going to do react element person and I'm going to do it three times.
115
00:08:14,540 --> 00:08:20,240
Now, if we check our application, we'll see, right, we rendered our person component.
116
00:08:21,370 --> 00:08:24,460
Three times you are a developer, you are a developer, you are a developer.
117
00:08:25,420 --> 00:08:30,280
Now, we can't go to these valleys, but what if we wanted to do the same thing we did with our other
118
00:08:30,280 --> 00:08:30,760
components?
119
00:08:30,760 --> 00:08:30,970
Right.
120
00:08:31,000 --> 00:08:32,559
We wanted to use props?
121
00:08:32,710 --> 00:08:35,850
Well, because it's just a functional component, as we had before.
122
00:08:36,190 --> 00:08:38,860
We can do exactly that can pass props into this.
123
00:08:39,159 --> 00:08:39,520
Right.
124
00:08:39,640 --> 00:08:43,600
And instead of you're going to do something like props that name right.
125
00:08:43,929 --> 00:08:45,610
Or proper occupation.
126
00:08:45,610 --> 00:08:50,200
And these are whatever it is that the attributes are that we want for this component to take.
127
00:08:50,200 --> 00:08:50,480
Right.
128
00:08:51,010 --> 00:08:57,580
So now, if we wanted to actually add those in, we would do our name inside of that second argument
129
00:08:57,580 --> 00:08:58,540
with that object.
130
00:08:58,540 --> 00:08:58,740
Right.
131
00:08:58,780 --> 00:09:02,110
We do our attributes of name of Yehuda.
132
00:09:03,180 --> 00:09:04,620
And then occupation.
133
00:09:06,130 --> 00:09:06,910
Of developer.
134
00:09:08,810 --> 00:09:13,160
And now we can do the same thing, right, for these other three.
135
00:09:14,720 --> 00:09:16,310
And this one will be Andre.
136
00:09:18,630 --> 00:09:19,560
Instructor.
137
00:09:22,870 --> 00:09:24,430
And let's say, Ted.
138
00:09:25,430 --> 00:09:26,450
And he's an actor.
139
00:09:27,310 --> 00:09:27,660
Right.
140
00:09:28,600 --> 00:09:30,370
Now, if we look at our application.
141
00:09:31,770 --> 00:09:34,880
We see we can pass in our props, right?
142
00:09:35,990 --> 00:09:40,770
That's all we were doing when we were writing our functional components and our class components.
143
00:09:41,030 --> 00:09:45,710
It's just that with JSF we don't have to call react element constantly.
144
00:09:45,950 --> 00:09:46,310
Right.
145
00:09:46,460 --> 00:09:49,850
It knows to read from that Telmo mark up that we were writing.
146
00:09:50,570 --> 00:09:56,050
And that's why J sex is so good when we use it with react, because this is kind of redundant, right?
147
00:09:56,420 --> 00:09:58,730
It's just a quality of life improvement.
148
00:09:59,690 --> 00:10:04,430
Now, you might be wondering how would we do it with our class components?
149
00:10:04,850 --> 00:10:06,090
It's actually the exact same.
150
00:10:06,110 --> 00:10:07,220
So instead of an app.
151
00:10:08,390 --> 00:10:15,290
I'm just going to put I'm just to make a class app extends react component, right, because component
152
00:10:15,530 --> 00:10:19,730
is just the method that exists on react, right.
153
00:10:19,760 --> 00:10:19,970
Sorry.
154
00:10:19,970 --> 00:10:22,520
It's a class that exists on Riak that it exposes to us.
155
00:10:23,090 --> 00:10:25,360
And then we have access that render again.
156
00:10:25,970 --> 00:10:31,730
And in that render, I'm just going to return what it is that we had here.
157
00:10:35,730 --> 00:10:42,580
And now, instead of app being a functional component, we're still rendering our class component of
158
00:10:42,580 --> 00:10:42,770
that.
159
00:10:43,860 --> 00:10:44,760
And if we look.
160
00:10:46,230 --> 00:10:47,800
We'll see their application stays the same.
161
00:10:48,420 --> 00:10:52,500
That's all it is, that's all Riak does for us.
162
00:10:52,500 --> 00:10:59,610
It helps us build out these views and that's why react and react, Dom, are such great libraries,
163
00:10:59,610 --> 00:11:07,020
because it just helps us simply build out our views and manage figuring out what the right thing in
164
00:11:07,020 --> 00:11:08,550
our views is to update.
14218
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.