All language subtitles for 011 Optimizing the Custom Hook Store_en

af Afrikaans
sq Albanian
am Amharic
ar Arabic
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 Download
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:02,410 --> 00:00:08,980 With all of that configured, there's one additional thing we can do, a little optimization we can 2 00:00:08,980 --> 00:00:15,250 put into place now that we have our own management system in the product item, just fall there. 3 00:00:15,250 --> 00:00:20,890 I can add a console lock statement where I say rendering so that we can see whenever diskettes re rendered. 4 00:00:21,870 --> 00:00:26,370 Now, if you go to products, this gets rendered four times because I have four products, let me clear 5 00:00:26,370 --> 00:00:32,430 that and click favorite you see now it is all the rendered four times actually should only render one 6 00:00:32,430 --> 00:00:35,280 time because this item here changed. 7 00:00:35,280 --> 00:00:37,350 We're updating the button look and so on. 8 00:00:37,530 --> 00:00:40,350 So therefore this definitely should be rendered. 9 00:00:40,350 --> 00:00:41,160 That makes sense. 10 00:00:41,700 --> 00:00:44,760 But the above three items shouldn't really be rendered. 11 00:00:44,790 --> 00:00:45,830 They weren't touched. 12 00:00:46,080 --> 00:00:51,050 So to avoid that these items, Virender, you could of course say, yeah, sure, let's wrap them in 13 00:00:51,070 --> 00:00:51,840 react memo. 14 00:00:51,840 --> 00:00:57,180 Right, react memo around these items should make sure they don't re render if they're props. 15 00:00:57,180 --> 00:00:59,160 Didn't change at the props for the other items. 16 00:00:59,160 --> 00:01:00,240 Certainly didn't change. 17 00:01:00,240 --> 00:01:02,850 They have the same title, the same favorite status and so on. 18 00:01:03,760 --> 00:01:10,720 You'll notice if we do that, they still remember the reason for that is our custom hook in each product 19 00:01:10,720 --> 00:01:11,300 item. 20 00:01:11,320 --> 00:01:17,860 I'm using use store, so I use my custom hook and in that custom hook, we use use the state. 21 00:01:18,520 --> 00:01:25,930 So whenever set state is called here, the component that uses this hook will be rendered makes sense. 22 00:01:25,930 --> 00:01:27,130 It's the intended behavior. 23 00:01:27,130 --> 00:01:28,450 It's the default behavior. 24 00:01:29,600 --> 00:01:37,130 Well, we can fix this or improve this in our custom hook here in the U.S. or Hook, we could accept 25 00:01:37,130 --> 00:01:41,360 an argument which is maybe you should listen and we can even assign a default value here. 26 00:01:41,360 --> 00:01:42,160 Let's say true. 27 00:01:43,010 --> 00:01:49,040 Now, we can use that to determine whether we actually want to register a listener for this component 28 00:01:49,040 --> 00:01:49,550 or not. 29 00:01:49,700 --> 00:01:54,470 So for this component, which is using a store, because if we have a component which only uses our 30 00:01:54,470 --> 00:02:00,860 store to dispatch actions like our product item is doing it, well, then we don't want to listen to 31 00:02:00,860 --> 00:02:03,600 changes inside of this product item component. 32 00:02:03,650 --> 00:02:05,470 We're not interested in state changes. 33 00:02:05,480 --> 00:02:08,660 I'm only using the hook so that I can dispatch actions. 34 00:02:09,440 --> 00:02:18,260 So in the store, Jaspal, we can now go to use effect and check if should lessness true and only add 35 00:02:18,260 --> 00:02:19,700 our listener if it is. 36 00:02:20,820 --> 00:02:26,400 And, of course, also only tried to clean it up if we are listening, so only if should listen is true, 37 00:02:26,760 --> 00:02:29,420 only then I'll try to clean that up. 38 00:02:29,790 --> 00:02:33,960 That also means that should listen is now a dependency of use effect. 39 00:02:33,960 --> 00:02:35,040 So we should add their. 40 00:02:36,540 --> 00:02:41,370 Now, this allows us to do the following, we can go to the product item in here and use store, I can 41 00:02:41,370 --> 00:02:42,450 pass and false. 42 00:02:42,780 --> 00:02:46,920 So false is now a value for that should listen argument. 43 00:02:47,340 --> 00:02:50,720 So that means that in product item, I'm not setting up a listener. 44 00:02:50,820 --> 00:02:59,100 So this item here, this component should not register a listener in my global listeners area and therefore 45 00:02:59,100 --> 00:03:04,020 it shouldn't rebuild when our store changes because here I'm really not interested in store changes. 46 00:03:04,560 --> 00:03:09,600 Does store change about this single product, which I set to be a favorite is. 47 00:03:10,600 --> 00:03:16,540 Reaching does Eitam anyways, because dad is something I'm listening to in a product JS file where I 48 00:03:16,540 --> 00:03:21,940 rebuilt this list of products when, well, I mark something as a favorite and therefore this specific 49 00:03:21,940 --> 00:03:28,150 product item will get a new prop anyways that will go through Rick Memmo and therefore this single item 50 00:03:28,150 --> 00:03:30,490 will rebuild, but the other items shouldn't. 51 00:03:31,210 --> 00:03:34,080 So now let's save this and let's test it. 52 00:03:34,810 --> 00:03:37,090 Now we only see one rendering call here. 53 00:03:37,120 --> 00:03:42,880 If I mark this as a favorite and this makes way more sense than the four calls we saw before, because 54 00:03:42,880 --> 00:03:47,470 that only makes sense if we are rendering the entire list for the first time, but certainly not when 55 00:03:47,470 --> 00:03:49,080 we only update one item. 56 00:03:49,480 --> 00:03:55,060 So that's a tiny optimization, which we can also put in place here and which also hopefully shows you 57 00:03:55,060 --> 00:03:58,480 the power of custom hooks and of this custom state management system. 58 00:03:58,780 --> 00:04:02,440 You can really optimize this for your requirements and your needs. 6054

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