All language subtitles for 016 Cleaning Up with useEffect()_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,520 --> 00:00:07,860 Instead of setting a timer for every effect, therefore having multiple timer isn't the end for every 2 00:00:07,860 --> 00:00:13,050 keystroke, we want to make sure we always clear the previous timer because it doesn't matter to us 3 00:00:13,050 --> 00:00:13,440 anymore. 4 00:00:13,470 --> 00:00:16,550 If there is a new keystroke, the old timer can be dismissed. 5 00:00:16,650 --> 00:00:23,310 We always just want to measure a change from the latest keystroke to well after the pause. 6 00:00:23,520 --> 00:00:27,690 We're not caring about an older keystroke, so we want to clean up that timer. 7 00:00:28,260 --> 00:00:34,350 The good thing is set time out in the end, gives you a reference, a pointer at the timer, which we 8 00:00:34,350 --> 00:00:36,750 can store in a constant timer here. 9 00:00:36,750 --> 00:00:39,410 And I'm doing this indie function we're passing to use effect. 10 00:00:39,630 --> 00:00:41,390 So this is the currently active timer. 11 00:00:41,970 --> 00:00:45,390 And now there's something on use a fact which I simply haven't shown you before. 12 00:00:45,960 --> 00:00:46,830 Use effect. 13 00:00:46,830 --> 00:00:50,600 Fact takes a function and dysfunction can actually return something. 14 00:00:51,240 --> 00:00:52,560 Let me shrink that if statement. 15 00:00:52,560 --> 00:00:53,130 It's still there. 16 00:00:53,130 --> 00:00:59,640 It's just shrunken so that we don't see it after days of Stef�n and most importantly, after this timer. 17 00:01:00,710 --> 00:01:06,020 But still, inside of that function, we pass to use effects at the end of this function, we can return 18 00:01:06,020 --> 00:01:08,920 something and thus far we haven't returned anything and use effect. 19 00:01:09,140 --> 00:01:12,470 Now, you don't need to return anything, but you can return something. 20 00:01:12,590 --> 00:01:15,700 But when you do return something, it always has to be a function. 21 00:01:16,460 --> 00:01:18,100 And this is a clean up function. 22 00:01:18,350 --> 00:01:19,160 It's a function. 23 00:01:19,160 --> 00:01:24,220 It will run right before this same use effect function will run the next time. 24 00:01:24,500 --> 00:01:29,440 So not after this function is done, but before the next time it will run. 25 00:01:29,900 --> 00:01:30,560 So on. 26 00:01:30,560 --> 00:01:37,640 The first render does executes and this does not execute, but then on the first keystroke. 27 00:01:38,560 --> 00:01:44,830 We clean up the old effect, run a new one on the second keystroke, we clean up the previous effect, 28 00:01:44,830 --> 00:01:46,440 run a new one ends on. 29 00:01:46,450 --> 00:01:47,340 That's how this works. 30 00:01:47,710 --> 00:01:53,020 And here in the clean up function, we can call clear timeout and pass in timer. 31 00:01:53,020 --> 00:01:56,980 Does is how you clear a timer in JavaScript to clear that previous timer. 32 00:01:57,900 --> 00:02:04,680 Again, clean up will run for the previous effect before the new effect is applied, so this cleans 33 00:02:04,680 --> 00:02:11,160 up the old timer before it sets a new one, and this ensures that we always only have one ongoing timer, 34 00:02:11,460 --> 00:02:16,340 which is, of course, better because we don't have all these redundant timers in memory. 35 00:02:16,530 --> 00:02:18,780 We have only one timer instead. 36 00:02:20,940 --> 00:02:22,320 So finally, save this. 37 00:02:23,450 --> 00:02:27,530 We won't see a strong difference here, still the same behavior as before. 38 00:02:29,140 --> 00:02:35,230 Still works as before, but it's more memory efficient because we don't have all these old timers going 39 00:02:35,230 --> 00:02:36,710 on behind the scenes and memory. 40 00:02:37,200 --> 00:02:42,370 Instead, we only have one timer at a time like this. 41 00:02:43,210 --> 00:02:46,000 So this is how this works, does how we can work with that. 42 00:02:46,090 --> 00:02:50,860 And this is how you can clean up your effects, which you might need in situations like this. 43 00:02:50,980 --> 00:02:56,860 But also, for example, if you're setting up Sun subscription to a Web service or anything like that, 44 00:02:56,860 --> 00:03:02,580 anything which might emit values regularly, you want to clean up your old subscription. 45 00:03:02,590 --> 00:03:07,450 That case, for example, if you're setting a new one with use effect and here it's the same with the 46 00:03:07,450 --> 00:03:13,420 timer when a clear our old timer when we're setting a new one so that we don't have all these redundant 47 00:03:13,420 --> 00:03:18,580 timers in our memory, which ultimately will take up a lot of memory and make our app slower. 4925

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