Shadowing Practice: Learn useMemo In 10 Minutes - Learn English Speaking with Video

Bir pratik modu seçin

Her mod tam ekran bir pratik odası açar.

139 cümleler
Cümleler çok kısa veya çok uzun ise, ayarlamak için Düzenle'ye tıklayın.
1
Hello everyone, welcome back to my React Hooks series, where in this video we're going to take a look at use memo,
2
how it works, and when you should actually use it.
3
And if you're interested in diving into React even deeper, make sure to check out my full
4
React course, which I'm going to link down in the description below.
5
Have you wanted free web hosting that doesn't suck?
6
Well you're in luck because today's video sponsor, Atlantic .net, is giving you an entire year -long free trial of their hosting.
7
And if you use the code
8
Kyle when you check out, you're going to get an additional $50 of credit that you can use towards whatever you want on the hosting platform.
9
On top of that, this hosting platform has powerful servers with great data reliability
10
and redundancy so you know that your site is going to be there and running with the data you want it to.
11
So make sure you use the code
12
Kyle in the link down in the description below to get your free hosting.
13
Welcome back to Web Dev Simplified.
14
My name's Kyle and my job is to simplify the web for you so you can start building your dream project sooner.
15
So if that sounds interesting, make sure you subscribe to the channel for more videos just like this.
16
Now to get started, I just have some really basic boilerplate code set up for us to test our application.
17
I'm going to walk through it real quick so you know exactly what we're doing.
18
I just have a simple single component called app, which has two pieces of state.
19
One is a number, which we can control by this input over here on the right.
20
And the second one is a Boolean for dark or light, which is toggled by this change theme button on the right side of our screen.
21
Then what we do is we have a function which doubles our number, so just multiplies by two, but this function is very slow.
22
If I scroll down here, you can see I just have a really long for loop
23
that just loops doing nothing for a really long time to emulate what would happen in a really slow, long -running, complex function.
24
Obviously, since this function just multiplies by two, all this code is doing is making the function really slow.
25
And if I change this number, for example, by clicking this up arrow, you're going to see it takes about a second,
26
half a second for it to actually double the number.
27
So you can see this function is quite slow to execute.
28
Now continuing onward, we just have a variable here,
29
which is taking this dark boolean and changing if we have a dark or light theme down here.
30
And then lastly, over here, we just have the output code which changes our number
31
when we update here and also toggles our theme when we click this button.
32
So that's just the basics of our code
33
and you may think okay this is fine code it's working great
34
and the slowness is you know not that bad
35
but it only is going to be slow when we update our number but actually that's incorrect thinking.
36
If we click our change theme button you're going to notice we have the same delay.
37
I'm going to click
38
it now you can see it takes about half a second
39
to a second for it to actually change the actual theme
40
and the reason for that is because when you update state in React, it's going to re -render your entire component.
41
So it's going to run this entire function from top to bottom,
42
which means that this slow function gets called every single time that we render our app component.
43
So whether we're changing the theme, whether we're actually updating the number here, or whether some other component is causing this component to re -render,
44
you're going to be forcing it to go through that slow function over and over and over again.
45
And this is a really big performance problem when you have these slow functions that don't really change that often.
46
So React has a built -in way to solve this with a hook which is called use memo.
47
So we can import this use memo hook just like this.
48
And memo here stands for memoization, which essentially is the idea of caching a value so you don't have to re -compute it every single time.
49
So in our example, this slow function here takes an input of number,
50
and it's always going to give us the same output every time we give it the same input.
51
So we can cache that input value number and the output it gives us.
52
That way if the number doesn't change we don't have to recalculate our slow function over and over and over again.
53
And the easy way to use this is we just call use memo and we're going to pass it in a function.
54
And this function is going to be the thing that we actually mem -wise.
55
So this is the thing that we're caching which in our case is going to be this slow function.
56
We just want to make sure we return this slow function here, get the result from it.
57
And then just like all of the other hooks that we talked about like useEffect for example, we're going to have a list of dependencies here.
58
And in our case the only dependency of this is going to be our number here.
59
Our number is the only thing that changes.
60
And when our number changes we need to rerun the code inside this useMemo hook
61
but if our number doesn't change we don't need to rerun this slow function code.
62
So with that one simple change let's save and see what happened to our app.
63
It's loading over here we can change this to for example one
64
and you can see it has a kind of delay change it up again it's going to have a delay.
65
When we click change theme you're going to notice this is instantaneous I can click it as much as I want to.
66
And that's because when we go through our code, we click change theme, it causes our component to re -render.
67
So it calls this function, does all this stuff, and it gets down to use memo.
68
And it says, well, our number is exactly the same as what it was last time.
69
So we're not going to recall this slow function here because we already know what the result is.
70
It's the exact same thing as it was last time.
71
So we're saving ourselves from having to recalculate this number with the slow function,
72
and we only are forcing ourselves to do this when we actually update this number inside of our input here.
73
So we're essentially only running this slow code when we have to, and not running it when we don't actually need to.
74
Now this seems really nice, and you may think, let me just use memo everywhere, why not just memwise everything?
75
Like this theme styles here, why don't I memwise that based on this dark boolean variable?
76
And the reason you don't want to memwise everything is because it does give you some performance overheads and some memory overhead.
77
For example, this use memo function must be called every single render of your component.
78
So you're calling an additional function.
79
And also it's saving the value, this previous value in some memory variable.
80
So you're forcing your memory to get larger every time you use memo
81
because you have to store an additional variable in memory to store that previous value.
82
Now this isn't a huge deal.
83
But especially where you don't need it,
84
it's going to cause additional memory usage and additional performance problems when just not using it would have been better.
85
So I highly recommend you only use memo in this case when you actually need the performance benefits, when the function you're calling is incredibly slow.
86
Then use memo is great.
87
But there's also a second use case for use memo, and that is something called referential equality.
88
And if you aren't really familiar with value versus reference in JavaScript.
89
I have a video on that topic I'll link in the cards in description.
90
But essentially what that is saying is when you try to compare two different variables in JavaScript,
91
it's going to compare their reference in the case of objects and arrays.
92
So for example, this theme styles here is a specific object.
93
And if I were to duplicate this theme styles, for example, theme styles two right here,
94
you would think that theme styles and theme style 2 are equal to each other, but in JavaScript they reference different objects.
95
They have the same values in the object, but the actual reference to the object itself is different.
96
So these two values are actually not equal to each other, which is something really important.
97
And as you know, inside of hooks in React, we have this array here of all of our dependencies, and when our dependencies change,
98
it's going to rerun our hook.
99
So let's take a quick example where we have a use effect
100
and we want to run this use effect every single time that our theme styles here changes.
101
So we're just going to have a really simple console .log
102
theme changed and down here inside of our dependencies I'm going to have our theme styles.
103
Let's just get rid of this console down here and of course we need to make sure we import use effect
104
just like that.
105
And now if I just really quickly inspect this page here, pull this over, go to the console,
106
you can see we get our theme changed being printed out.
107
And when we change our theme, you can see it's continually printing out theme changed.
108
But a problem you'll notice if I clear this out is when we change our number, it's also causing this theme change to be run.
109
And the reason for that is that referential equality.
110
What's happening is every time we run our function, we get a new theme styles object being created.
111
And this new theme style object is not the same as the old theme styles, even though they have the exact same values in the object,
112
they reference different places in memory.
113
And that's really important to know.
114
So in order to make sure that we only ever run useEffect when our theme style object actually gets re -updated, we can use memo again.
115
So what we can do is wrap this in a use memo, make sure you pass it a function,
116
and in here we're just going to return that object.
117
We just indent all this properly, and in here for our dependencies we're just going to put
118
that dark variable because that's the only thing that this object depends on.
119
Now if we were to rerun this you can see a change in our theme causes this to update our theme, logs it out, but
120
when we change our number you're going to notice we don't actually get anything printed in our console
121
and only when we click change theme.
122
And the reason for this is that now we are wrapping this object inside of memorization.
123
Essentially, if our dark variable doesn't change, we don't re -update our theme styles.
124
So we get the exact same reference as we had the previous time we rendered our app.
125
So now our use effect is comparing our old theme styles with our new theme styles, but they both reference the exact same object.
126
So these are the two big use cases for use memo.
127
The first and most obvious is when you want to make a slow function,
128
wrap it in this use memo so that it doesn't recompute every single time you render your component,
129
and it only computes when you actually need the value from that function since the input's actually changed.
130
The second use case, which is a little bit trickier, is this idea of referential equality.
131
Whenever you want to make sure the reference of an object
132
or an array is exactly the same as it was the last time you rendered if none of the internal workings changed,
133
you're going to want to use memo here to make sure
134
that you only update the reference of
135
that object whenever the actual contents of the object change instead of updating every single time you render.
136
And that's all there is to the use memo hook.
137
If you enjoyed this video, make sure to check out my full react course linked in the description to get a full overview of everything
138
you need to know about react.
139
Thank you very much for watching and have a good day.

Uygulamayı İndir

Akıcı konuşmak için ihtiyacınız olan her şey

AI TelaffuzHer cümleyi puanla
IPA AlıştırmasıHer sesi ustalaştır
Kelime BilgisiKelime bankanızı oluşturun
Kelime OyunuOynarken öğrenin

Aynı Kanal

FOR YOU

Video Öner

Bu dersin kelimeleri ve konuşma notları

Bu konuşma dersi “Learn useMemo In 10 Minutes” videosuna dayanıyor. En çok tekrarlanan kelimeler: theme, function, memo, slow, object. Bu videoda gölgeleme çalışması için 139 cümle ve 2166 kelime var. Konuşma bölümü 10:41 sürüyor. Konuşmacı hızlı konuşuyor, dakikada yaklaşık 203 kelime; bu yüzden birbirine bağlanan ve zayıflayan sesler duyacaksınız. Kelimelerin %87’i İngilizcede en sık kullanılan 3.000 kelime arasında, bu yüzden kelime dağarcığını takip etmek kolay.

Bu videodaki önemli kelimeler

Videodan öğrenmeye değer 15 kelime, telaffuzu ve anlamıyla:

KelimeTelaffuzAnlam
memo isim/ˈmɛməʊ̯/kısa not
render fiil/ˈɹɛn.dɚ/eylemek
hook isim/hʊk/kanca, çengel
component isim/kəmˈpoʊ.nənt/parça, bileşen
react fiil/ɹiːˈækt/reaksiyon göstermek
variable sıfat[ˈvæɹ.i.ə.bl̩]değişken
compare fiil/kəmˈpɛɚ/karşılaştırmak, kıyaslamak
output isim/ˈaʊtpʊt/çıktı
delay isim/dɪˈleɪ̯/gecikme, rötar
equality isim/ɪˈkwɑ.lɪ.ti/eşitlik
array isim/əˈɹeɪ/elbise, giyecek
cache isim/kæʃ/önbellek
loop isim/luːp/ilik
import isim/ˈɪm.pɔɹt/ithal
overhead isim/ˈəʊvəˌhɛd/genel giderler

Duyacağınız deyimsel fiiller

KelimeAnlam
check out fiilgözden geçirmek

Bu videodaki dil bilgisi

Konuşmacının en çok kullandığı yapılar, videodaki sözcüklerin aynısıyla:

YapıVideoda
Edilgen yapı be + fiilin üçüncü hâli — kimin yaptığı değil, ne olduğu önemliis toggled · is called · must be called
İlgi cümlecikleri who / which + cümle — bir kişi ya da şey hakkında ek bilgiapp, which has · light, which is · hook which is

Dikkat edilecek telaffuzlar

Konuşmacı we're, you're, don't gibi kısaltılmış biçimleri 48 kez kullanıyor. Bunları duyduğunuz gibi kısa söyleyin.

  • “sh” ve “zh” sesleri: essentially /ɪˈsɛnʃəli/, cache /kæʃ/, referential /ɹɛfəˈɹɛnʃəl/, memoization /ˌmɛmoʊaɪˈzeɪʃən/, memorization /ˈmem(ə)ɹaɪˌzeɪʃn̩/
  • Uzun kelimeler — vurguyu doğru yere koyun: dependency /dɪˈpɛndənsi/, essentially /ɪˈsɛnʃəli/, equality /ɪˈkwɑ.lɪ.ti/, incredibly /ɪŋˈkɹɛdɪbli/, continually /kənˈtɪnjuəli/

Türkçe konuşanların zorlandığı sesler:

  • /w/ — dudaklar yuvarlak, /v/ değil: equality /ɪˈkwɑ.lɪ.ti/, onward /ˈɒnwəd/
  • Kelime başındaki ünsüz kümesi — araya ünlü eklemeyin: sponsor /ˈspɒn.səː/, tricky /ˈtɹɪk.i/, scroll /skɹoʊl/, duplicate /ˈd(j)uː.plɪˌkeɪt/
  • /æ/ — “e”den daha açık: react /ɹiːˈækt/, variable [ˈvæɹ.i.ə.bl̩], wrap /ɹæp/, cache /kæʃ/, arrow /ˈæɹəʊ/

Bu videoyla nasıl çalışılır

  1. Videonun tamamını konuşmadan bir kez dinleyin ve bilmediğiniz kelimeleri not edin.
  2. 0,75× hızla başlayın, cümle cümle tekrar edin ve kolaylaşınca normal hıza dönün.
  3. Kendinizi kaydedin ve orijinaliyle karşılaştırın; memo, render, hook gibi kelimelere özellikle dikkat edin.

Gölgeleme Tekniği Nedir?

Gölgeleme, başlangıçta profesyonel tercüman eğitimi için geliştirilen ve çok dilli Dr. Alexander Arguelles tarafından popüler hale getirilen, bilim destekli bir dil öğrenme tekniğidir. Yöntem basit ama güçlüdür: ana dili İngilizce olan bir sesi dinler ve hemen yüksek sesle tekrar edersiniz — konuşmacıyı 1-2 saniye gecikmeyle takip eden bir gölge gibi. Pasif dinleme veya dilbilgisi alıştırmalarının aksine, gölgeleme beyninizi ve ağız kaslarınızı gerçek konuşma kalıplarını eşzamanlı olarak işlemeye ve yeniden üretmeye zorlar. Araştırmalar, telaffuz doğruluğu, tonlama, ritim, bağlı konuşma, dinleme anlama ve konuşma akıcılığını önemli ölçüde geliştirdiğini göstermektedir — bu da onu IELTS Konuşma hazırlığı ve gerçek dünya İngilizce iletişimi için en etkili yöntemlerden biri yapar.

Shadowing tekniği: adım adım eksiksiz rehberi okuyun →