Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,360 --> 00:00:06,210
So in order for us to understand, I'm just going to look quickly at this life cycle component that
2
00:00:06,210 --> 00:00:08,900
I've written, it's just called life cycles, right?
3
00:00:09,090 --> 00:00:09,900
That's all it is.
4
00:00:09,900 --> 00:00:16,110
It's just a component called Life Cycles, which is a class component, extending the Riak component.
5
00:00:17,050 --> 00:00:17,440
So.
6
00:00:18,490 --> 00:00:25,360
Inside of here are the possible life-cycle methods that we want to look at, and inside of each one,
7
00:00:25,390 --> 00:00:31,600
I'm just logging the name of the life cycle that it is, so that when it gets called and we look in
8
00:00:31,600 --> 00:00:36,670
our console, we'll see the order in which they're getting fired.
9
00:00:37,330 --> 00:00:37,720
Now.
10
00:00:38,820 --> 00:00:45,000
Before we take a look into what these life cycles are, there's actually a diagram we can look at on
11
00:00:45,000 --> 00:00:45,960
the React website.
12
00:00:47,570 --> 00:00:55,490
And on this diagram, it will show us in this graph form when each method fires, depending on what
13
00:00:55,490 --> 00:00:56,960
phase the component is in.
14
00:00:57,990 --> 00:01:01,530
So the first phase we're going to look at is the mounting phase.
15
00:01:02,840 --> 00:01:11,150
The mounting phase is the phase when the component is being put on the dome for the first time.
16
00:01:13,190 --> 00:01:19,250
So when it's mounting, when it's in the mountain phase, it starts before our component is actually
17
00:01:19,520 --> 00:01:26,580
on our door, right before it's on our page, when it starts mounting, it first looks at the component.
18
00:01:26,600 --> 00:01:29,180
So for us, our life cycles component.
19
00:01:30,080 --> 00:01:36,530
And then it sees the constructor and it calls the constructor first, so inside of our constructor we
20
00:01:36,530 --> 00:01:43,850
have our super right and the super is pretty much just a method on all classes inside of their constructors
21
00:01:44,210 --> 00:01:53,120
that say, if I'm extending from some other class component, I want you pull in all of their methods
22
00:01:53,120 --> 00:01:54,350
and all of their functionality.
23
00:01:54,770 --> 00:01:55,100
Right.
24
00:01:55,310 --> 00:02:00,680
Which might sound complicated, but all you need to know is that what that does is it allows our class
25
00:02:00,680 --> 00:02:07,130
component to have access to these lifecycle components, because you can see it as if these lifecycle
26
00:02:07,130 --> 00:02:13,580
components and when they get called in the order of all this functionality is actually originally bound
27
00:02:13,580 --> 00:02:19,140
to this react component, this Riak class component that we need to borrow from.
28
00:02:19,160 --> 00:02:25,640
So we're essentially saying extend me all of that functionality into my class component called lifecycle,
29
00:02:26,450 --> 00:02:30,470
and then the constraints of the constructor when we call super, it's like, OK, this is when I want
30
00:02:30,470 --> 00:02:32,750
you to give me all that functionality, right.
31
00:02:32,960 --> 00:02:40,070
So that I can bind it all to my class component inside of the constructor as well is when we can declare
32
00:02:40,070 --> 00:02:41,430
our state right.
33
00:02:41,450 --> 00:02:47,330
So when we call this DOT state, we do it inside of our constructor specifically for this reason, because
34
00:02:47,330 --> 00:02:52,400
this is when our state becomes initialized on our class.
35
00:02:54,270 --> 00:02:59,280
So the constructor gets called first for this reason, so that our components, other lifecycle methods,
36
00:02:59,640 --> 00:03:07,170
if they need to use the state, are aware of the state because it's initialized inside of our constructor.
37
00:03:08,620 --> 00:03:17,260
After the constructor, call it, then, calls are render method and the render method is when our component
38
00:03:17,860 --> 00:03:19,190
tells JavaScript.
39
00:03:19,210 --> 00:03:23,710
OK, this is what I want you to display in terms of HTML.
40
00:03:24,580 --> 00:03:28,780
This is also where any prop values get evaluated in the HTML.
41
00:03:29,200 --> 00:03:34,450
So because we're passing in that text string, this is when JavaScript is like, oh, I'm calling the
42
00:03:34,450 --> 00:03:35,740
render method on this class.
43
00:03:35,740 --> 00:03:42,820
I'm also going to evaluate the value of this prop text and then turn it into something that I can display
44
00:03:43,270 --> 00:03:44,290
in the HTML.
45
00:03:44,290 --> 00:03:50,470
And that's how we're able to see that string value that we get passed in as a prop or anything, for
46
00:03:50,470 --> 00:03:50,960
that matter.
47
00:03:51,310 --> 00:03:55,060
This evaluation is happening inside of our render call.
48
00:03:56,580 --> 00:04:03,810
After the render comes, when React actually updates the dawn, right, or it makes updates to our component,
49
00:04:03,810 --> 00:04:09,390
but the main thing here is where reacts like, OK, now that I know what the component looks like because
50
00:04:09,390 --> 00:04:14,430
of the render and I know what state and whatever things are on the class component because of the constructor,
51
00:04:14,670 --> 00:04:16,769
I'm now going to put it on the page.
52
00:04:16,769 --> 00:04:17,700
I'm going to mount it.
53
00:04:18,390 --> 00:04:21,990
And then once it mounts, the component did mount.
54
00:04:23,170 --> 00:04:30,040
Lifecycle method gets fired, and inside of here is where it's like, OK, the component has mounted,
55
00:04:30,040 --> 00:04:32,160
it's in its base state, right?
56
00:04:32,650 --> 00:04:34,110
It's properly evaluated.
57
00:04:34,660 --> 00:04:37,810
Then I'm going to call my lifecycle method component did mount.
58
00:04:38,830 --> 00:04:40,210
And if we look at our application.
59
00:04:41,700 --> 00:04:46,770
We'll see that that's the order that it happens, we got the constructor first, then the renderer gets
60
00:04:46,770 --> 00:04:50,730
called and then our component dismount gets called.
61
00:04:51,360 --> 00:04:59,100
And usually this is where after we've loaded our base, our class component inside of a component did
62
00:04:59,100 --> 00:05:02,970
mount is where we start to do things like our API calls.
63
00:05:03,360 --> 00:05:09,330
If you remember from our earlier instance where we made an API call to get all the users for our monster's
64
00:05:09,330 --> 00:05:09,930
Rolodex.
65
00:05:10,740 --> 00:05:17,010
And the reason for this is because we want to load the base component first before we start fetching
66
00:05:17,010 --> 00:05:23,520
data and updating our component so that it looks different from the Baystate.
67
00:05:23,520 --> 00:05:23,730
Right.
68
00:05:23,730 --> 00:05:26,820
Because we don't know how long the API call might take.
69
00:05:27,390 --> 00:05:28,470
Latency might be slow.
70
00:05:29,070 --> 00:05:32,640
Your connection might be poor, but this is the order.
71
00:05:32,670 --> 00:05:39,540
And how we should leverage this lifecycle method is that we wait for the base component to mount and
72
00:05:39,540 --> 00:05:46,200
then we're like, OK, let's use our component at Mount Method to update it into its next state and
73
00:05:46,200 --> 00:05:47,370
this next state.
74
00:05:47,370 --> 00:05:51,510
This updating phase is the next phase of our component.
75
00:05:52,920 --> 00:05:55,440
After the base mounted state.
76
00:05:56,340 --> 00:05:57,300
Is on our Don.
77
00:05:58,830 --> 00:06:02,910
So let's take a look at the next phase, the updating phase.
7742
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.