All language subtitles for 009 Passing State Data Across Components_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,220 --> 00:00:06,689 So that was a lot of talking about you state, but of course, as I said, it is important. 2 00:00:07,260 --> 00:00:13,080 But now let's continue and let's make sure that we actually can press that button and we do at this 3 00:00:13,080 --> 00:00:14,130 ingredient somewhere. 4 00:00:14,970 --> 00:00:18,310 So for that in to submit handler, I want to submit my data. 5 00:00:18,990 --> 00:00:25,020 Now, let's say we're managing our ingredients not in ingredient form, but in the ingredients. 6 00:00:25,020 --> 00:00:28,020 Just following Folland ingredients component there. 7 00:00:29,330 --> 00:00:34,250 And just because I'm seeing it here, I'm creating that component with the function keyword like this 8 00:00:34,580 --> 00:00:40,310 in ingredient form, I'm creating it like this, storing it in a constant, then by using a eral function 9 00:00:40,310 --> 00:00:42,530 on the right side of the const, it's totally up to you. 10 00:00:42,530 --> 00:00:46,040 What you want to use both creates valid functional components. 11 00:00:46,190 --> 00:00:48,750 Both has nothing to do with react hooks. 12 00:00:49,640 --> 00:00:56,780 So back in the ingredients function here, which we just to avoid confusion could also write like this 13 00:00:57,530 --> 00:00:58,780 in its ingredients function. 14 00:00:58,790 --> 00:00:59,990 I have two ingredients for him. 15 00:00:59,990 --> 00:01:03,920 And here in this functional component, I want to manage my ingredients. 16 00:01:04,160 --> 00:01:08,930 I guess that makes a lot of sense because there will always later output the list of ingredients. 17 00:01:09,170 --> 00:01:13,800 So it is a component that has access to both our input and to our output later. 18 00:01:14,690 --> 00:01:17,000 So I want to manage the ingredients in there. 19 00:01:18,090 --> 00:01:24,120 Does, of course, means that we want to add use state here, because our list of ingredients, our 20 00:01:24,120 --> 00:01:28,710 array of ingredients, of course, will be some state that she'll survive rewriter cycles that will 21 00:01:28,710 --> 00:01:32,200 change over time and where every change should be rendered. 22 00:01:32,200 --> 00:01:38,340 This so that once we do add a list to output our ingredients, well, we can actually see some change 23 00:01:38,340 --> 00:01:39,480 there when we add ingredient. 24 00:01:40,020 --> 00:01:45,630 So in the ingredients functional component, I'll again use aerator structuring to manage my ingredients 25 00:01:45,630 --> 00:01:48,510 and to have a set ingredients function. 26 00:01:49,410 --> 00:01:55,350 And in there with you state, I start with an empty array here, I use an array because ingredients, 27 00:01:55,350 --> 00:02:00,720 of course, will be a list of ingredients and we will always update that list as a whole when we add 28 00:02:00,720 --> 00:02:03,800 an ingredient or when we later delete an ingredient and so on. 29 00:02:04,680 --> 00:02:06,210 So we got our ingredients. 30 00:02:07,260 --> 00:02:16,140 Now, we can also import the ingredient list component from the ingredient list, just file, which 31 00:02:16,140 --> 00:02:22,290 I prepared for you, you can just add it here, ingredient list and ingredient list. 32 00:02:22,290 --> 00:02:27,180 This component actually takes a property ingredients, which is then output. 33 00:02:27,360 --> 00:02:32,910 And there besides the title and the amount, I also want to have an I.D. that IDs then used as a key. 34 00:02:33,880 --> 00:02:40,540 So egregious, I want to parse ingredients, this prop, which ingredient list expects to ingredient 35 00:02:40,540 --> 00:02:46,000 list and the value here will be my ingredients up there now can be confusing because it's always the 36 00:02:46,000 --> 00:02:46,970 same name. 37 00:02:47,280 --> 00:02:53,620 So maybe we name disappear yuzu ingredients and name this here is set user ingredients. 38 00:02:54,130 --> 00:02:58,990 You don't have to rename this just because you rename debt, but to really make it clear that these 39 00:02:58,990 --> 00:02:59,770 two belong together. 40 00:03:00,010 --> 00:03:05,290 I like to have the same names just as a set in front of our updating function here and now. 41 00:03:05,290 --> 00:03:08,540 User ingredients is what I pass here to the ingredients prop. 42 00:03:08,590 --> 00:03:10,990 So I hope this is clear which ingredients is what. 43 00:03:11,140 --> 00:03:13,320 That's the prop of the ingredient list. 44 00:03:14,200 --> 00:03:15,860 So we're passing this in here now. 45 00:03:15,880 --> 00:03:18,950 The ingredient form should be able to add a new ingredient. 46 00:03:19,480 --> 00:03:22,960 So let's define a function here in the ingredients. 47 00:03:23,840 --> 00:03:28,010 Functional component, add ingredient or add ingredient. 48 00:03:29,230 --> 00:03:36,040 Handler, maybe, and that's a function which will ultimately receive a new ingredient here, which 49 00:03:36,040 --> 00:03:38,150 should store design our ingredients array. 50 00:03:38,620 --> 00:03:42,040 So here the idea will be to call set user ingredients. 51 00:03:42,370 --> 00:03:48,050 And now important, we'll need to update the existing list of ingredients and add a new one. 52 00:03:48,460 --> 00:03:54,340 Now, that means we depend on the current state and therefore it's best if we use the function of form 53 00:03:54,340 --> 00:03:57,310 where we're guaranteed to get the latest state. 54 00:03:57,820 --> 00:04:04,480 So we get our previous ingredients here, our old array, basically the current state, the most recent 55 00:04:04,690 --> 00:04:06,190 state of this list here. 56 00:04:06,850 --> 00:04:13,830 And we return a new era where I use all previous ingredients. 57 00:04:13,990 --> 00:04:20,230 This is a spread operator taking all elements of our old array and adding them as elements to this new 58 00:04:20,230 --> 00:04:22,660 era, which I'm constructing with the square brackets. 59 00:04:23,020 --> 00:04:27,400 And then I add one new element here, and that's the ingredient we're getting now. 60 00:04:27,400 --> 00:04:33,580 Important ingredient we're getting from the ingredient form will have a title and an amount, but probably 61 00:04:33,580 --> 00:04:37,130 not an ID because the idea should be somehow auto generated. 62 00:04:37,570 --> 00:04:40,600 Now I'll later use a Web server which does this for us. 63 00:04:40,840 --> 00:04:41,230 For now. 64 00:04:41,230 --> 00:04:47,800 Let's create a new object here with an ID, which for now can just be MAFF random to string. 65 00:04:48,520 --> 00:04:53,470 And that's not truly a unique ID, but unique enough for for our cases here. 66 00:04:53,480 --> 00:05:01,210 It's a good ID and then I of course want to keep my title and my amount from ingredient and we can again 67 00:05:01,210 --> 00:05:04,000 use to spread operator on ingredient now. 68 00:05:04,870 --> 00:05:08,650 So on this argument we're getting because this argument will be an object. 69 00:05:08,650 --> 00:05:14,410 Let's say the spread operator then takes all key value Keres from that object and adds to ask value 70 00:05:14,410 --> 00:05:15,760 pairs to this new object. 71 00:05:16,410 --> 00:05:22,200 So now we're adding a new object with an ID tideline amount to our list of ingredients here. 72 00:05:22,250 --> 00:05:23,940 That's the add ingredient handler. 73 00:05:24,580 --> 00:05:30,820 Now we need to pass a pointer at that add ingredient handler to the ingredient form because that is 74 00:05:30,820 --> 00:05:33,660 where we want to trigger the addition of an ingredient. 75 00:05:33,670 --> 00:05:38,530 Right, because that's where we have our button that well submits this form. 76 00:05:39,100 --> 00:05:45,640 This button is of type submit, therefore it triggers the ends up here and the handler and in here I 77 00:05:45,640 --> 00:05:51,730 now want to well, call something which I'm getting from the ingredients component. 78 00:05:52,660 --> 00:05:58,000 So let's say we pass in a prop which could be named on add ingredient and the name is totally up to 79 00:05:58,000 --> 00:05:58,300 you. 80 00:05:58,600 --> 00:06:01,290 And there we point at the add ingredient handler. 81 00:06:01,660 --> 00:06:04,810 So this is how you parse function references down to components. 82 00:06:04,810 --> 00:06:05,020 Right. 83 00:06:05,020 --> 00:06:06,340 You learned that from the course. 84 00:06:06,490 --> 00:06:08,950 Hasn't changed, has nothing to do with react hooke's. 85 00:06:09,670 --> 00:06:15,670 So now we'll have on add ingredient prop in the ingredient for him and dad will have a pointer at this 86 00:06:15,670 --> 00:06:16,240 function. 87 00:06:17,180 --> 00:06:23,840 So in the ingredient form, in the supplement handler, we can call props on add ingredient as a function 88 00:06:23,840 --> 00:06:29,660 because again, this will hold a pointer at that function in the ingredients, Jaspal, and there will 89 00:06:29,660 --> 00:06:34,430 pass the object because here I expect to get ingredients as object. 90 00:06:35,370 --> 00:06:42,690 I pass an object which has a title in amount, so your title is my entered title. 91 00:06:43,600 --> 00:06:47,660 And amount is my entered amount just like that. 92 00:06:48,040 --> 00:06:49,690 So this is getting sent to the. 93 00:06:50,990 --> 00:06:56,900 Add ingredient handler, this will add a new ingredient and update our ingredients array, and we're 94 00:06:56,900 --> 00:06:59,330 passing those ingredients array to the ingredient list. 95 00:06:59,360 --> 00:07:04,190 So now our hope would be to see changes in that list when we add an ingredient. 96 00:07:04,460 --> 00:07:06,010 So here's our ingredient list. 97 00:07:06,410 --> 00:07:08,450 Now, let's add five apples. 98 00:07:09,320 --> 00:07:16,280 And we're getting an error now, it is error is coming from the ingredient list there, I'm registering 99 00:07:16,280 --> 00:07:23,560 a click on ingredients to bind to and remove item that is something we'll need later to remove ingredients. 100 00:07:24,140 --> 00:07:29,060 So for now, let's simply go to the ingredient list component we're using in the ingredients component 101 00:07:29,360 --> 00:07:32,210 and pass on removalist prop in there. 102 00:07:32,570 --> 00:07:38,360 And this should point at a function which for now simply doesn't do anything just so that ingredient 103 00:07:38,360 --> 00:07:40,550 list does receive a function and bind. 104 00:07:40,550 --> 00:07:41,630 Delford does work. 105 00:07:44,440 --> 00:07:49,720 So with debt, let's try this again, let's add five apples and here they are now clicking on them, 106 00:07:49,720 --> 00:07:53,620 doesn't do anything for now, but we can now add our ingredients. 11288

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