All language subtitles for 011 Dispatching Actions From Inside Components_en

af Afrikaans
ak Akan
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bem Bemba
bn Bengali
bh Bihari
bs Bosnian
br Breton
bg Bulgarian
km Cambodian
ca Catalan
ceb Cebuano
chr Cherokee
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
ee Ewe
fo Faroese
tl Filipino
fi Finnish
fr French
fy Frisian
gaa Ga
gl Galician
ka Georgian
de German
el Greek
gn Guarani
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian
is Icelandic
ig Igbo
id Indonesian
ia Interlingua
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
rw Kinyarwanda
rn Kirundi
kg Kongo
ko Korean
kri Krio (Sierra Leone)
ku Kurdish
ckb Kurdish (Soranî)
ky Kyrgyz
lo Laothian
la Latin
lv Latvian
ln Lingala
lt Lithuanian
loz Lozi
lg Luganda
ach Luo
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mfe Mauritian Creole
mo Moldavian
mn Mongolian
my Myanmar (Burmese)
sr-ME Montenegrin
ne Nepali
pcm Nigerian Pidgin
nso Northern Sotho
no Norwegian
nn Norwegian (Nynorsk)
oc Occitan
or Oriya
om Oromo
ps Pashto
fa Persian Download
pl Polish
pt-BR Portuguese (Brazil)
pt Portuguese (Portugal)
pa Punjabi
qu Quechua
ro Romanian
rm Romansh
nyn Runyakitara
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
sh Serbo-Croatian
st Sesotho
tn Setswana
crs Seychellois Creole
sn Shona
sd Sindhi
si Sinhalese
sk Slovak
sl Slovenian
so Somali
es Spanish
es-419 Spanish (Latin American)
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
tt Tatar
te Telugu
th Thai
ti Tigrinya
to Tonga
lua Tshiluba
tum Tumbuka
tr Turkish
tk Turkmen
tw Twi
ug Uighur
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
wo Wolof
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu
Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated: 1 00:00:02,090 --> 00:00:04,150 Now for dispatching actions, 2 00:00:04,150 --> 00:00:07,320 I first of all, want to have two new buttons here 3 00:00:07,320 --> 00:00:09,460 which allow me to dispatch actions 4 00:00:09,460 --> 00:00:12,173 for incrementing and decrementing. 5 00:00:13,410 --> 00:00:15,110 So here I'll add a new div. 6 00:00:15,110 --> 00:00:18,800 And in that div I'll just add two buttons. 7 00:00:18,800 --> 00:00:23,800 The first one says increment, the second one says decrement. 8 00:00:24,950 --> 00:00:27,320 So that we have these buttons. 9 00:00:27,320 --> 00:00:28,630 And now to add some spacing, 10 00:00:28,630 --> 00:00:31,690 I'll quickly dive into counter.module.css 11 00:00:32,650 --> 00:00:37,470 and add this selector .counter button 12 00:00:37,470 --> 00:00:39,473 which selects these buttons here. 13 00:00:40,360 --> 00:00:42,430 And I'll just give them a margin of one rem 14 00:00:42,430 --> 00:00:45,743 in all directions, just so that we have some spacing. 15 00:00:46,810 --> 00:00:49,640 Now, with that added, with that setup, 16 00:00:49,640 --> 00:00:52,180 now we want to wire up those two buttons, 17 00:00:52,180 --> 00:00:53,990 increment and decrement, 18 00:00:53,990 --> 00:00:58,173 so that they do increase or decrease the counter by one. 19 00:00:59,150 --> 00:01:02,140 Now we know that we need to dispatch an action before that. 20 00:01:02,140 --> 00:01:05,830 But how does that work from inside a react component? 21 00:01:05,830 --> 00:01:08,180 Well, there is another hook which we can use, 22 00:01:08,180 --> 00:01:10,313 the use dispatch hook. 23 00:01:11,440 --> 00:01:15,930 When we call use dispatch here, 24 00:01:15,930 --> 00:01:18,770 we don't pass any argument to it, 25 00:01:18,770 --> 00:01:23,040 but instead, this gives us back a dispatch function 26 00:01:23,040 --> 00:01:24,570 which you can execute. 27 00:01:24,570 --> 00:01:27,300 So this patch here is a function, 28 00:01:27,300 --> 00:01:28,850 a function which we can call, 29 00:01:28,850 --> 00:01:33,423 which will dispatch an action against our Redux store. 30 00:01:34,770 --> 00:01:35,603 So therefore now, 31 00:01:35,603 --> 00:01:39,360 I'll add two new functions here in this counter component. 32 00:01:39,360 --> 00:01:42,800 The increment handler 33 00:01:45,000 --> 00:01:49,650 and the detriment handler. 34 00:01:49,650 --> 00:01:54,390 So two new functions which will wire up to the buttons. 35 00:01:54,390 --> 00:01:56,880 And in the increment handler, 36 00:01:56,880 --> 00:01:59,900 we want to use this dispatch function and execute it 37 00:01:59,900 --> 00:02:03,980 to dispatch a new action and then do what we learned. 38 00:02:03,980 --> 00:02:07,720 An action is an object with a type property. 39 00:02:07,720 --> 00:02:09,380 So let's add such an object here 40 00:02:09,380 --> 00:02:12,810 as an argument to the dispatch function call 41 00:02:12,810 --> 00:02:16,260 so that we dispatch this specific object. 42 00:02:16,260 --> 00:02:18,780 And then the value for type should be one 43 00:02:18,780 --> 00:02:22,313 of the identifiers we use in our Redux store reducer. 44 00:02:23,470 --> 00:02:25,520 So here in the reducer function, 45 00:02:25,520 --> 00:02:27,930 we handle the action type increment 46 00:02:27,930 --> 00:02:30,230 and the action type detriment. 47 00:02:30,230 --> 00:02:33,730 So we should dispatch one of these two identifiers. 48 00:02:33,730 --> 00:02:36,510 Of course, exactly these identifiers, 49 00:02:36,510 --> 00:02:38,963 without any typos or changes. 50 00:02:40,460 --> 00:02:44,910 So back in counter here, I'll dispatch increment 51 00:02:46,360 --> 00:02:48,790 and then here in the detriment handler 52 00:02:48,790 --> 00:02:51,860 I'll dispatch an object with a type property 53 00:02:51,860 --> 00:02:54,083 with a value of decrement. 54 00:02:55,170 --> 00:02:58,750 Now we need to wire up those two functions to the buttons. 55 00:02:58,750 --> 00:03:03,750 So this first button we add an on click prop 56 00:03:04,260 --> 00:03:06,550 and point at the increment handler. 57 00:03:06,550 --> 00:03:07,680 And on the second button 58 00:03:07,680 --> 00:03:10,583 we do the same for the decrement handler. 59 00:03:11,620 --> 00:03:13,483 And if we do that and save this, 60 00:03:14,550 --> 00:03:19,250 if we now click increment, you see the counter increases 61 00:03:19,250 --> 00:03:22,860 and if you click decrement, it decreases. 62 00:03:22,860 --> 00:03:26,760 So now we're able to use what we learned about Redux 63 00:03:26,760 --> 00:03:31,193 in this react demo, in this react component here. 4946

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