All language subtitles for 016 Working with _Event Props_ (Passing Function As Props)_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,150 --> 00:00:04,800 To get rid of the modal and the Backdrop now 2 00:00:04,800 --> 00:00:06,930 we need to change the state again 3 00:00:06,930 --> 00:00:10,020 from setModalIsOpen true to false. 4 00:00:10,020 --> 00:00:12,160 We need to call setModalIsOpen again 5 00:00:12,160 --> 00:00:14,023 and pass false as a value. 6 00:00:15,010 --> 00:00:19,100 The problem just is when do we wanna do that? 7 00:00:19,100 --> 00:00:21,830 We wanna do that when the Backdrop is clicked 8 00:00:21,830 --> 00:00:24,910 or when the Cancel or Confirm buttons are clicked. 9 00:00:24,910 --> 00:00:26,020 We don't wanna do that 10 00:00:26,020 --> 00:00:28,573 if the modal itself is clicked for example. 11 00:00:29,920 --> 00:00:31,520 Now for the Backdrop click, 12 00:00:31,520 --> 00:00:33,460 you could think that on Backdrop, 13 00:00:33,460 --> 00:00:36,040 you simply add onClick again 14 00:00:36,040 --> 00:00:38,710 and then we add a second function here 15 00:00:38,710 --> 00:00:43,140 the closeModalHandler, let's say 16 00:00:44,030 --> 00:00:48,150 and there we call setModalIsOpen and set this to false. 17 00:00:48,150 --> 00:00:52,110 And then we point at this closeModalHandler here 18 00:00:52,110 --> 00:00:54,200 as a value for onClick, 19 00:00:54,200 --> 00:00:56,483 just as we did it with the button in the end. 20 00:00:57,700 --> 00:00:59,140 But that won't work. 21 00:00:59,140 --> 00:01:00,500 If we save that 22 00:01:01,630 --> 00:01:02,940 and I reload, 23 00:01:02,940 --> 00:01:04,900 I can click the Backdrop the entire day 24 00:01:04,900 --> 00:01:06,453 the modal won't close. 25 00:01:07,340 --> 00:01:08,840 The reason for this is that, 26 00:01:08,840 --> 00:01:12,950 the Backdrop like the modal is our own component. 27 00:01:12,950 --> 00:01:16,140 These are not built-in components. 28 00:01:16,140 --> 00:01:18,630 So they don't know the onClick prop. 29 00:01:18,630 --> 00:01:23,560 Our own components have to be configured 100% by us. 30 00:01:23,560 --> 00:01:27,450 They have no built-in props which we can use. 31 00:01:27,450 --> 00:01:29,250 To be precise, they actually do 32 00:01:29,250 --> 00:01:31,920 but only for some very special cases 33 00:01:31,920 --> 00:01:35,350 and not for event listeners like this. 34 00:01:35,350 --> 00:01:38,910 So if you wanna make sure that our onClick prop exists 35 00:01:38,910 --> 00:01:42,140 in the Backdrop component, we have to add code 36 00:01:42,140 --> 00:01:45,790 to this component function to support this prop. 37 00:01:45,790 --> 00:01:48,330 And for this we can go to the component function 38 00:01:48,330 --> 00:01:50,780 and accept this props. 39 00:01:50,780 --> 00:01:53,460 Argument here does props parameter 40 00:01:53,460 --> 00:01:56,260 and then here, we can of course work 41 00:01:56,260 --> 00:01:59,870 with the onClick prop or any other name we want. 42 00:01:59,870 --> 00:02:02,370 It's totally up to you because it's our component. 43 00:02:03,490 --> 00:02:07,510 But here we can, for example, expect a onClick prop 44 00:02:07,510 --> 00:02:10,810 because I'm setting this here in the to-do component, 45 00:02:10,810 --> 00:02:14,100 and we actually expect a function as a value 46 00:02:14,100 --> 00:02:16,210 on this onClick prop 47 00:02:16,210 --> 00:02:17,890 because in the to-do component 48 00:02:17,890 --> 00:02:20,830 I do pass in a function in the end. 49 00:02:20,830 --> 00:02:22,640 I point at a function 50 00:02:22,640 --> 00:02:25,470 which means I pass a point or two to function 51 00:02:25,470 --> 00:02:27,823 as a value it for this prop. 52 00:02:29,020 --> 00:02:31,200 Now in the Backdrop component 53 00:02:31,200 --> 00:02:33,640 we actually wanna call this function, 54 00:02:33,640 --> 00:02:36,740 which we receive on the onClick prop 55 00:02:36,740 --> 00:02:38,800 when this div is clicked. 56 00:02:38,800 --> 00:02:41,770 Now the div is a built-in component again, 57 00:02:41,770 --> 00:02:44,040 so it does have onClick prop 58 00:02:44,040 --> 00:02:46,000 and now we could simply point 59 00:02:46,000 --> 00:02:49,320 at props onClick as a value here. 60 00:02:49,320 --> 00:02:51,330 By doing this we would in the end 61 00:02:51,330 --> 00:02:55,760 forward the function which we receive on our props here 62 00:02:55,760 --> 00:02:57,900 on our onClick prop 63 00:02:57,900 --> 00:03:02,170 into that div on it's onClick prop. 64 00:03:02,170 --> 00:03:04,550 And these names don't have to be equal. 65 00:03:04,550 --> 00:03:08,000 We could expect a onCancel prop here instead 66 00:03:08,000 --> 00:03:11,903 and in to do component rename this to onCancel. 67 00:03:12,850 --> 00:03:15,873 It's our components so we can name this however we want. 68 00:03:16,820 --> 00:03:19,810 Now if we do that and save all the files, 69 00:03:19,810 --> 00:03:22,670 if I reload, now we can close the modal 70 00:03:22,670 --> 00:03:24,560 by clicking the Backdrop 71 00:03:24,560 --> 00:03:27,070 because now we're using a prop 72 00:03:27,070 --> 00:03:29,420 to pass a function as a value. 73 00:03:29,420 --> 00:03:31,850 And that's a pattern which can be confusing 74 00:03:31,850 --> 00:03:33,840 and might look strange at first, 75 00:03:33,840 --> 00:03:36,390 but keep in mind that in Java script 76 00:03:36,390 --> 00:03:39,660 functions are first class objects. 77 00:03:39,660 --> 00:03:42,550 You can pass them around as values 78 00:03:42,550 --> 00:03:44,500 just as you can pass strings 79 00:03:44,500 --> 00:03:48,180 and arrays and objects and numbers as values. 80 00:03:48,180 --> 00:03:50,940 Hence you can pass a function as arguments 81 00:03:50,940 --> 00:03:54,540 to another function and therefore also as a value 82 00:03:54,540 --> 00:03:57,250 for a prop to a number of component. 83 00:03:57,250 --> 00:04:00,640 And then that function which we receive in that component 84 00:04:00,640 --> 00:04:03,320 can be executed in that component 85 00:04:03,320 --> 00:04:06,540 or as we're doing it here, it can be forwarded 86 00:04:06,540 --> 00:04:10,700 to yet another element another component. 87 00:04:10,700 --> 00:04:13,210 Now we can use that same approach 88 00:04:13,210 --> 00:04:17,140 in the modal component for canceling and confirming. 89 00:04:17,140 --> 00:04:22,140 There we could add functions like the cancelHandler. 90 00:04:22,410 --> 00:04:25,700 and then let's say the confirmHandler 91 00:04:25,700 --> 00:04:27,560 and kick off different logic 92 00:04:27,560 --> 00:04:30,490 depending on which button was clicked, 93 00:04:30,490 --> 00:04:32,720 but in this case, I'll simply 94 00:04:32,720 --> 00:04:35,470 in the end run the same code in both functions. 95 00:04:35,470 --> 00:04:38,160 Nonetheless, we can bind the first button 96 00:04:38,160 --> 00:04:41,020 with the onClick prop to cancelHandler, 97 00:04:41,020 --> 00:04:43,300 and here it has to be onClick 98 00:04:43,300 --> 00:04:45,790 because that's not a custom component, 99 00:04:45,790 --> 00:04:47,170 but a built-in one. 100 00:04:47,170 --> 00:04:50,540 So here we can't come up with any other name. 101 00:04:50,540 --> 00:04:53,610 And for the Confirm button I'll also add onClick 102 00:04:53,610 --> 00:04:55,493 and point at the confirmHandler. 103 00:04:56,620 --> 00:04:58,230 And now in these functions 104 00:04:58,230 --> 00:05:00,810 we can run any code we want. 105 00:05:00,810 --> 00:05:02,890 In this case though I also wanna 106 00:05:02,890 --> 00:05:04,660 just close the modal. 107 00:05:04,660 --> 00:05:08,310 So again, I'll just accept the props parameter here 108 00:05:08,310 --> 00:05:09,920 and then cancelHandler, 109 00:05:09,920 --> 00:05:14,150 I'll just execute props on Cancel let's say 110 00:05:14,150 --> 00:05:15,580 in the confirmHandler 111 00:05:15,580 --> 00:05:18,633 I'll execute props on Confirm. 112 00:05:19,530 --> 00:05:22,340 And hence instead of defining these functions here 113 00:05:22,340 --> 00:05:23,820 and pointing at them here 114 00:05:23,820 --> 00:05:27,270 we could have also just forwarded props onCancel here 115 00:05:27,270 --> 00:05:28,960 like this. 116 00:05:28,960 --> 00:05:31,010 Just as we did it for the Backdrop. 117 00:05:31,010 --> 00:05:33,290 I'm just showing this alternative approach 118 00:05:33,290 --> 00:05:35,040 to make it crystal clear 119 00:05:35,040 --> 00:05:37,210 that you can execute these functions 120 00:05:37,210 --> 00:05:39,230 which you receive through props. 121 00:05:39,230 --> 00:05:41,640 You can forward them to other elements 122 00:05:41,640 --> 00:05:43,280 if that's what you need to do 123 00:05:43,280 --> 00:05:46,990 but you can also execute them anywhere in your components. 124 00:05:46,990 --> 00:05:49,650 And hence, I'm using this alternative setup 125 00:05:49,650 --> 00:05:52,300 with these extra wrapper functions 126 00:05:52,300 --> 00:05:53,883 at which I then point here. 127 00:05:55,250 --> 00:05:58,800 And now we've got our onCancel and onConfirm prop 128 00:05:58,800 --> 00:06:01,730 which are expected on that modal component. 129 00:06:01,730 --> 00:06:05,410 So in the place where we use the modal component, 130 00:06:05,410 --> 00:06:09,387 we should add onCancel and onConfirm. 131 00:06:10,880 --> 00:06:12,680 And here in both cases 132 00:06:12,680 --> 00:06:15,730 I'll just point at the closeModalHandler 133 00:06:15,730 --> 00:06:17,330 because as mentioned before, 134 00:06:17,330 --> 00:06:19,500 here I got no special logic 135 00:06:19,500 --> 00:06:21,383 I just wanna close the modal. 136 00:06:23,420 --> 00:06:27,060 With that if we save this and reload 137 00:06:27,060 --> 00:06:30,840 we cannot just close the modal by clicking the Backdrop 138 00:06:30,840 --> 00:06:35,030 but also by clicking Cancel or by clicking Confirm. 139 00:06:35,030 --> 00:06:37,910 And that works for every to-do here. 140 00:06:37,910 --> 00:06:41,530 For all to-dos the modal works in the same way. 141 00:06:41,530 --> 00:06:44,050 And that's there for another very important 142 00:06:44,050 --> 00:06:46,390 building block of react. 143 00:06:46,390 --> 00:06:50,900 Props are important for building reusable components, 144 00:06:50,900 --> 00:06:54,360 state is important for changing what we see 145 00:06:54,360 --> 00:06:56,450 on the screen dynamically 146 00:06:56,450 --> 00:06:59,030 for adding or removing elements 147 00:06:59,030 --> 00:07:01,240 for changing text on the screen 148 00:07:01,240 --> 00:07:06,023 or like in this case for showing and hiding an overlay. 11269

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