シャドーイング練習: Learn useMemo In 10 Minutes - 動画で英語スピーキングを学ぶ

練習モードを選ぶ

各モードは全画面の練習ルームで開きます。

139 文
文が短すぎたり長すぎる場合は、Editをタップして調整してください。
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.

アプリをダウンロード

流暢に話すために必要なすべて

AI発音採点文ごとに採点
IPA練習すべての音をマスター
単語学習自分の単語帳を作る
単語ゲーム遊びながら覚える

同じチャンネル

FOR YOU

おすすめ動画

このレッスンの語彙とスピーキングのポイント

このスピーキングレッスンは、動画「Learn useMemo In 10 Minutes」を教材にしています。 繰り返し出てくる語は次のとおりです:theme, function, memo, slow, object。 この動画には、シャドーイング用の文が139文、単語が2166語あります。 音声の長さは10:41です。 話す速さは速く、1分あたり約203語です。音のつながりや弱く発音される音が多くなります。 単語の87%は英語の頻出3,000語に含まれるため、語彙は分かりやすいです。

この動画の重要語彙

動画に出てくる覚えておきたい単語15語を、発音と意味つきで紹介します。

単語発音意味
memo 名詞/ˈmɛməʊ̯/メモ
hook 名詞/hʊk/鉤, フック
component 名詞/kəmˈpoʊ.nənt/部分
variable 形容詞[ˈvæɹ.i.ə.bl̩]可変, 変えられる
dependency 名詞/dɪˈpɛndənsi/付属品
compare 動詞/kəmˈpɛɚ/比べる, 比較する
output 名詞/ˈaʊtpʊt/出力
delay 名詞/dɪˈleɪ̯/遅れ, 遅延
equality 名詞/ɪˈkwɑ.lɪ.ti/平等, 均等
wrap 動詞/ɹæp/包む, 包装する
cache 名詞/kæʃ/キャッシュ
loop 名詞/luːp/ループ
import 名詞/ˈɪm.pɔɹt/輸入品
overhead 名詞/ˈəʊvəˌhɛd/オーバーヘッド, 間接費
topic 名詞/ˈtɑpɪk/話題, テーマ

動画に出てくる句動詞

単語意味
check out 動詞試験する, 検査する

この動画の文法

話し手がよく使っている文型を、動画の実際の表現とともに紹介します。

文型動画での表現
受動態 be + 過去分詞 — 誰がするかより、何が起きるかに焦点を当てるis toggled · is called · must be called
関係詞節 who / which + 節 — 人や物について情報を加えるapp, which has · light, which is · hook which is

注意したい発音

話し手はwe're, you're, don'tなど、短縮形や弱形を48回使っています。聞こえたとおりの短い形で発音しましょう。

  • 「sh」と「zh」の音: essentially /ɪˈsɛnʃəli/, cache /kæʃ/, referential /ɹɛfəˈɹɛnʃəl/, memoization /ˌmɛmoʊaɪˈzeɪʃən/, memorization /ˈmem(ə)ɹaɪˌzeɪʃn̩/
  • 長い単語(アクセントの位置に注意): dependency /dɪˈpɛndənsi/, essentially /ɪˈsɛnʃəli/, equality /ɪˈkwɑ.lɪ.ti/, incredibly /ɪŋˈkɹɛdɪbli/, continually /kənˈtɪnjuəli/

日本語話者が苦手な音:

  • /r/ と /l/ の区別 — /l/ は舌先を歯茎につけ、/r/ はどこにもつけない: variable [ˈvæɹ.i.ə.bl̩], recall /ɹɪˈkɔl/, incredibly /ɪŋˈkɹɛdɪbli/, scroll /skɹoʊl/, referential /ɹɛfəˈɹɛnʃəl/
  • /v/ — /b/ にならないように、上の歯を下唇に当てる: variable [ˈvæɹ.i.ə.bl̩], overhead /ˈəʊvəˌhɛd/, server /ˈsɝvɚ/, solve /sɒlv/, versus /ˈvɝsəs/
  • /f/ — 「フ」ではなく、上の歯と下唇で出す: referential /ɹɛfəˈɹɛnʃəl/, simplify /ˈsɪmplɪfaɪ/

この動画での練習方法

  1. まず声を出さずに動画を最後まで聞き、知らない単語をメモします。
  2. まず0.75倍速で一文ずつシャドーイングし、慣れてきたら通常の速度に戻します。
  3. 自分の声を録音して元の音声と比べます。memo, hook, componentなどの単語に特に注意しましょう。

シャドーイングとは?英語上達に効果的な理由

シャドーイング(Shadowing)は、もともとプロの通訳者養成プログラムで開発された言語学習法で、多言語習得者として知られるDr. Alexander Arguelles によって広く普及されました。方法はシンプルですが非常に効果的:ネイティブスピーカーの英語を聞きながら、1〜2秒の遅延で声に出してすぐに繰り返す——まるで「影(shadow)」のように話者を追いかけます。文法ドリルや受動的なリスニングと異なり、シャドーイングは脳と口の筋肉が同時にリアルタイムで英語を処理・再現することを強制します。研究により、発音精度、抑揚、リズム、連音、リスニング力、そして会話の流暢さが大幅に向上することが確認されています。IELTSスピーキング対策や自然な英語コミュニケーションを目指す方に特におすすめです。

シャドーイングのやり方: ステップ別の完全ガイドを読む →