All language subtitles for 044 React Lifecycle Methods - Updating_en

af Afrikaans
sq Albanian
am Amharic
ar Arabic Download
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bn Bengali
bs Bosnian
bg Bulgarian
ca Catalan
ceb Cebuano
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
tl Filipino
fi Finnish
fr French
fy Frisian
gl Galician
ka Georgian
de German
el Greek
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian
is Icelandic
ig Igbo
id Indonesian
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
km Khmer
ko Korean
ku Kurdish (Kurmanji)
ky Kyrgyz
lo Lao
la Latin
lv Latvian
lt Lithuanian
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mn Mongolian
my Myanmar (Burmese)
ne Nepali
no Norwegian
ps Pashto
fa Persian
pl Polish
pt Portuguese
pa Punjabi
ro Romanian
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
st Sesotho
sn Shona
sd Sindhi
si Sinhala
sk Slovak
sl Slovenian
so Somali
es Spanish
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
te Telugu
th Thai
tr Turkish
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu
or Odia (Oriya)
rw Kinyarwanda
tk Turkmen
tt Tatar
ug Uyghur
Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated: 1 00:00:00,660 --> 00:00:10,110 Now that we've taken a look at the mounting phase of our component after our component has been mounted 2 00:00:10,140 --> 00:00:16,650 onto the dam, any future updates either to the props to the state? 3 00:00:18,110 --> 00:00:21,800 Or us manually forcing an update on our component. 4 00:00:23,000 --> 00:00:27,860 Will cause our component to go into the updating phase. 5 00:00:29,320 --> 00:00:31,900 So what is the updating phase and what triggers updates? 6 00:00:32,680 --> 00:00:41,560 Well, if, for example, inside of our app Jass, we're passing in the text value off of this dot state 7 00:00:41,950 --> 00:00:49,660 right into our lifecycle method, which for us is the string where whenever we click the button, we 8 00:00:49,660 --> 00:00:52,360 just append underscore hello to that string. 9 00:00:52,360 --> 00:00:53,830 We just make it longer and longer. 10 00:00:53,950 --> 00:00:54,230 Right. 11 00:00:54,250 --> 00:00:55,270 Which we can see right here. 12 00:00:58,710 --> 00:01:06,120 Every time we update and click this and update our state and this new state value gets passed into our 13 00:01:06,120 --> 00:01:07,500 life cycle component. 14 00:01:08,490 --> 00:01:14,220 Our lifecycle component goes into the updating phase and it's like, oh, I got new props, I should 15 00:01:14,220 --> 00:01:21,360 probably re render my component, not Rimando or component is already mounted. 16 00:01:21,390 --> 00:01:23,960 It doesn't need to go through mounting again. 17 00:01:24,570 --> 00:01:29,940 It doesn't need to be destroyed because REACT doesn't want to create new elements for doing that is 18 00:01:29,940 --> 00:01:32,010 actually very costly on the browser. 19 00:01:32,760 --> 00:01:43,170 But selectively changing pieces of the HTML inside of our component is way easier because all it needs 20 00:01:43,170 --> 00:01:45,180 to change is this stop props that text. 21 00:01:45,180 --> 00:01:46,980 It doesn't need to change the H3. 22 00:01:47,220 --> 00:01:48,720 It doesn't need to change the div. 23 00:01:49,560 --> 00:01:52,430 So reacts like, OK, I'm just going to update this stuff. 24 00:01:52,440 --> 00:01:53,310 Props that text. 25 00:01:53,310 --> 00:02:01,950 Right, or I'm also going to run through those lifecycle methods that might be affected in this updating 26 00:02:01,950 --> 00:02:08,009 phase because the props have changed and maybe these lifecycle methods do use the props to do something. 27 00:02:09,150 --> 00:02:13,920 Right, that's all up to us and how we want to write our code, the promise of change. 28 00:02:14,490 --> 00:02:16,470 I'm going to start going through my update cycle. 29 00:02:16,860 --> 00:02:22,380 The update cycle could also be triggered if this dot set state gets called inside of our component. 30 00:02:22,980 --> 00:02:27,690 So we don't actually call that state inside of our life cycles class because we don't have state. 31 00:02:27,690 --> 00:02:28,650 Right, which is fine. 32 00:02:29,220 --> 00:02:34,450 But if we look at our app component, we do have state and we do cost that state whenever we click either 33 00:02:34,450 --> 00:02:35,090 of these buttons. 34 00:02:35,790 --> 00:02:42,060 So whenever we click one of these buttons react, we renders this component as well. 35 00:02:42,090 --> 00:02:48,900 It goes through the update phase of our app component as well, because there might be things inside 36 00:02:48,900 --> 00:02:55,710 of our component that depends on the state to determine what they need to do, including our render. 37 00:02:56,280 --> 00:03:00,180 If, for example, we were displaying this DOT state. 38 00:03:01,850 --> 00:03:09,590 Text inside of our component ourselves, the component needs to decide, OK, I should probably render 39 00:03:09,590 --> 00:03:15,310 because there's a chance that this component is rendering something on the state. 40 00:03:16,130 --> 00:03:17,660 So that's why it does it. 41 00:03:18,020 --> 00:03:21,290 It's like, OK, the components state has changed as well. 42 00:03:21,830 --> 00:03:26,270 Let's also run through our update phase for our component. 43 00:03:26,810 --> 00:03:31,670 And then finally, we can also force an update by calling this status update inside of our component 44 00:03:31,670 --> 00:03:32,160 anywhere. 45 00:03:32,750 --> 00:03:35,780 This forces the component to update everything. 46 00:03:35,930 --> 00:03:38,050 It just forces to go through the update phase. 47 00:03:38,780 --> 00:03:41,300 But inside of the update phase, it just. 48 00:03:42,360 --> 00:03:47,700 Goes through these following methods, so just like our mount, right, it also goes through the render 49 00:03:47,700 --> 00:03:54,060 again, because new props comes in or new state comes in, react has to go through its process of deciding, 50 00:03:54,390 --> 00:03:56,700 oh, what in my component has changed. 51 00:03:57,940 --> 00:04:03,010 And then it's going to update the dome, right, so it's going to update the dome with the changes that 52 00:04:03,010 --> 00:04:04,510 are required in that component. 53 00:04:04,990 --> 00:04:09,670 Again, we're not remounting that component, which is making the change, that piece of the component 54 00:04:09,670 --> 00:04:10,660 where it's affected. 55 00:04:12,110 --> 00:04:17,779 And then it calls component it update similar to component of Mt. It's the life cycle method that gets 56 00:04:17,779 --> 00:04:20,579 called after the updates have been made to the DON. 57 00:04:22,089 --> 00:04:22,720 And here. 58 00:04:24,270 --> 00:04:25,140 We can see this. 59 00:04:26,670 --> 00:04:31,290 When we click update, text, right, we see it called render, and then it calls our component it update. 60 00:04:34,490 --> 00:04:38,810 One thing I want us to look at is actually this life cycle method, so I'm just going to put it in here. 61 00:04:39,080 --> 00:04:40,910 It's should a component update. 62 00:04:42,080 --> 00:04:52,240 Should component update is a cycle method that determines whether or not this whole chain needs to happen. 63 00:04:53,170 --> 00:05:01,120 And it actually exists between these things that would trigger this updating phase to happen. 64 00:05:02,270 --> 00:05:05,630 And the following Life-cycle methods to get triggered. 65 00:05:06,620 --> 00:05:08,900 She component update actually sits right here at. 66 00:05:09,780 --> 00:05:16,650 And what it does is it gets the props and then the next state, right, so it gets when props change, 67 00:05:16,650 --> 00:05:22,950 they come in as a parameter or when state changes, it also comes in as a parameter. 68 00:05:24,580 --> 00:05:30,250 And what happens is that based on the props, the new props that are coming in or the new state after 69 00:05:30,250 --> 00:05:37,570 we've called said state, we can determine whether or not we want to go through these other life-cycle 70 00:05:37,570 --> 00:05:42,370 methods, including actually re rendering our component right. 71 00:05:42,760 --> 00:05:46,140 Because if we don't want to render a component, we don't have to. 72 00:05:46,810 --> 00:05:50,680 And how we would do this is actually if we looked at our objects. 73 00:05:51,740 --> 00:05:58,380 So, for example, whenever set state gets called, we know that what gets happened is our render call 74 00:05:58,400 --> 00:06:00,160 gets called right in our component. 75 00:06:00,830 --> 00:06:06,980 So whenever we call sad state, we're actually re rendering this whole abcess component, which actually 76 00:06:06,980 --> 00:06:13,640 ends up re rendering the life cycles component, even if we were not passing this text in. 77 00:06:14,980 --> 00:06:21,550 This component, because it's a child of our arpeggios, gets re rendered, I can actually show you 78 00:06:21,550 --> 00:06:26,920 if I get rid of this prop so we're no longer passing the prop into our life cycles method, even though 79 00:06:26,920 --> 00:06:28,030 I click update text. 80 00:06:29,970 --> 00:06:35,160 You will see that our render method and then component, that update is getting called from a life cycle 81 00:06:35,250 --> 00:06:35,790 component. 82 00:06:36,420 --> 00:06:42,210 This is because of how reacts, no tree works, react, knows that inside of this component, any of 83 00:06:42,210 --> 00:06:49,740 the children might need to be rendered because it's just going to assume that everything in the render 84 00:06:49,770 --> 00:06:55,770 is affected possibly by the state changing or new props coming into this component. 85 00:06:56,250 --> 00:06:56,600 Right. 86 00:06:57,210 --> 00:07:02,810 So whenever a component gets updated rendered, all the children also get re rendered. 87 00:07:02,940 --> 00:07:09,090 And this happens whenever, again, as we saw props change or sets state gets called or force update, 88 00:07:09,120 --> 00:07:11,190 it's called inside of the component. 89 00:07:12,400 --> 00:07:19,300 Now, the reason this is important is because let's say we called set state on a property that are life-cycle 90 00:07:19,300 --> 00:07:20,620 method doesn't care about. 91 00:07:21,040 --> 00:07:26,590 Let's say, for example, we had another state property, I don't know, message. 92 00:07:26,590 --> 00:07:26,950 Right. 93 00:07:27,310 --> 00:07:33,060 And then this value we used somewhere else inside of this component, we don't pass it on to life cycles 94 00:07:33,070 --> 00:07:34,060 as a prop. 95 00:07:34,180 --> 00:07:35,420 We just use it somewhere else. 96 00:07:36,370 --> 00:07:41,860 Well, if at stake, it's called the upstate's this message we just saw that it's going to force our 97 00:07:41,860 --> 00:07:43,450 component to update. 98 00:07:43,450 --> 00:07:43,810 Right. 99 00:07:44,920 --> 00:07:46,030 And our component. 100 00:07:46,030 --> 00:07:51,550 If the state of Texas hasn't changed, why do we need to re render a life cycles component? 101 00:07:52,000 --> 00:07:54,000 That's a waste of processing power. 102 00:07:54,010 --> 00:07:56,220 It's it's slowing down our browser. 103 00:07:57,070 --> 00:08:01,570 So what we could do here is it allows us to selectively hijack. 104 00:08:02,460 --> 00:08:08,070 And not go through that Virender, right, we don't have to render our component. 105 00:08:09,800 --> 00:08:16,820 And here we can see we do that by what gets returned as a boolean value from should component update 106 00:08:17,630 --> 00:08:18,320 if we return. 107 00:08:18,320 --> 00:08:18,710 True. 108 00:08:19,890 --> 00:08:25,890 Then our component will update, it will continue, will go through the cycles, and it will run through 109 00:08:26,460 --> 00:08:27,540 that component and update. 110 00:08:29,090 --> 00:08:33,970 And here we actually see us logging the next prompts that we're getting, right? 111 00:08:34,429 --> 00:08:38,049 So whenever we collect update text, we see that the text is coming through. 112 00:08:38,299 --> 00:08:38,539 Right. 113 00:08:38,580 --> 00:08:41,230 That's the property, the new text property that we're getting. 114 00:08:42,230 --> 00:08:44,030 But if we return false. 115 00:08:45,650 --> 00:08:51,380 What happens is that it doesn't even go through any of those lifecycle methods except for a component 116 00:08:51,380 --> 00:08:51,710 update. 117 00:08:52,770 --> 00:08:57,390 Because when we return, false, we're saying, I don't want my company to render and the reason we 118 00:08:57,390 --> 00:09:02,730 would do this is, for example, if we were to check the next props that we're getting, if we see that 119 00:09:02,730 --> 00:09:08,420 the string value for our text has not changed, then we don't care to update them. 120 00:09:08,700 --> 00:09:09,660 We don't need to. 121 00:09:10,140 --> 00:09:11,520 There's no reason for us to do that. 122 00:09:12,180 --> 00:09:20,210 And here we will see that if we click up the text, we're getting this call, our component update. 123 00:09:20,400 --> 00:09:27,660 But because we're trying to false, it does not go through the next cycle methods that need to happen 124 00:09:27,660 --> 00:09:29,160 inside of our updating phase. 125 00:09:31,420 --> 00:09:37,630 And the reason we would do this, as I mentioned, is because maybe we don't want to remender because 126 00:09:37,660 --> 00:09:44,050 our techs didn't change and we can actually force this to happen if inside of our button click instead 127 00:09:44,050 --> 00:09:47,940 of a pending hello, we just keep the text as what it is. 128 00:09:47,950 --> 00:09:54,700 But because we're calling set state, we're forcing the state to change and because we're forcing the 129 00:09:54,700 --> 00:09:57,950 state to change or forcing react to re render our component. 130 00:09:58,870 --> 00:10:05,560 So now inside of our lifecycle methods, what we can do is here we can actually say we want to return 131 00:10:05,560 --> 00:10:06,520 instead of force. 132 00:10:06,550 --> 00:10:07,420 We want to return. 133 00:10:07,900 --> 00:10:15,380 If next Prof's text does not equal this stop props dot text. 134 00:10:15,940 --> 00:10:23,500 So if the current text is the same as the next prompt text, then don't render because there's no point 135 00:10:23,500 --> 00:10:23,940 to write. 136 00:10:23,980 --> 00:10:27,580 We don't need to render our component because our props have not changed. 137 00:10:28,830 --> 00:10:31,020 So now we'll see if we click update, text. 138 00:10:32,010 --> 00:10:32,820 It doesn't update. 139 00:10:33,700 --> 00:10:37,630 But if we go back and we say that, OK, now the text is changing. 140 00:10:38,530 --> 00:10:40,640 Well, then our component will update accordingly. 141 00:10:41,200 --> 00:10:43,810 So this is mainly just for performance. 142 00:10:44,740 --> 00:10:52,000 If the property's coming in are not different than the props that we already have, then there's no 143 00:10:52,000 --> 00:10:53,230 reason to render. 144 00:10:54,770 --> 00:11:05,720 Now, understanding this update phase is so fundamental to us becoming better react developers, because 145 00:11:05,720 --> 00:11:13,760 much of how code is structured and how the architecture for react is written is based around this update 146 00:11:13,760 --> 00:11:19,060 phase, because this is fundamentally what the Riak Library does for us. 147 00:11:19,490 --> 00:11:20,990 This is why we write components. 148 00:11:21,260 --> 00:11:28,070 This is why we break our code up the way it does, because this update phase is how Riak makes our lives 149 00:11:28,070 --> 00:11:30,830 easier for us whenever it updates the DOM. 150 00:11:31,810 --> 00:11:37,840 Based on new properties coming in, based on us calling substate or forcing updates inside of our components, 151 00:11:38,560 --> 00:11:46,720 this triggers a chain reaction of, for example, our app component, updating also its children, not 152 00:11:46,720 --> 00:11:50,860 only rendering itself, but rendering any child components it has. 153 00:11:51,310 --> 00:11:53,620 And then those components also update. 154 00:11:54,600 --> 00:12:01,890 But that's the thing, if we trigger big updates like this, there may not be a need to even update 155 00:12:01,890 --> 00:12:08,940 these components if, as we saw, the props do not actually change, if the props don't change, nothing 156 00:12:08,940 --> 00:12:10,530 about this component needs to update. 157 00:12:12,070 --> 00:12:20,050 So leveraging the life cycle methods will allow us to possibly improve the performance of our application, 158 00:12:20,680 --> 00:12:25,840 but also give us a better idea of when we should do what with our components. 159 00:12:26,440 --> 00:12:32,080 Now, of course, we're going to practice more and more with writing our components, building react 160 00:12:32,080 --> 00:12:32,860 applications. 161 00:12:33,610 --> 00:12:40,120 But just thinking and keeping this in the back of your mind as we code will help you better understand 162 00:12:40,330 --> 00:12:43,610 why we structure the code the way that it is. 163 00:12:44,320 --> 00:12:48,740 This will all make more and more sense the more you code in react. 164 00:12:49,240 --> 00:12:54,490 Now, I know this was a bit of a longer lesson, but now that we understand what the update phase, 165 00:12:54,520 --> 00:12:57,760 let's move on to the last phase, the UN mounting phase. 16480

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.