All language subtitles for 013 More on useEffect()_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,200 --> 00:00:07,600 Let's go to a research component, the search component should be responsible for it input field, where 2 00:00:07,600 --> 00:00:14,110 we, for example, can enter apples and then we only see while the items that matched his name and we're 3 00:00:14,110 --> 00:00:17,200 doing a full name search here, so we'll not search for app. 4 00:00:17,440 --> 00:00:19,420 But Apple gives us little apples. 5 00:00:19,810 --> 00:00:21,450 Bananas gives us little bananas. 6 00:00:21,460 --> 00:00:22,360 That's the idea here. 7 00:00:22,370 --> 00:00:27,160 Red notice doesn't work, of course, because the search as follows pretty empty and has no meaningful 8 00:00:27,160 --> 00:00:27,970 logic in there. 9 00:00:28,540 --> 00:00:32,130 It's time to now change this with the knowledge we gain thus far. 10 00:00:32,890 --> 00:00:41,260 First of all, let's make sure we manage to user input so we can add import use state here like that. 11 00:00:43,060 --> 00:00:50,380 Then here again, USERRA structuring to have the entered filter, let's say, and set entered filter 12 00:00:50,680 --> 00:00:52,420 and then use state. 13 00:00:53,250 --> 00:01:01,080 With an empty string and bind to stand there, bind the value to entered filter and bind on change here 14 00:01:01,560 --> 00:01:08,280 to a function it updates set entered filter, we get the event automatically passed in by react in the 15 00:01:08,280 --> 00:01:13,430 end and then we call set entered filter and we set this to event target value. 16 00:01:13,770 --> 00:01:15,540 So that's something we did before already. 17 00:01:15,960 --> 00:01:17,670 Just saving the value here. 18 00:01:18,150 --> 00:01:24,630 But now the idea is that whenever a user type something to you here, we try to fetch filter data from 19 00:01:24,630 --> 00:01:25,320 Firebase. 20 00:01:26,380 --> 00:01:28,540 How could we make this work? 21 00:01:29,260 --> 00:01:35,560 Well, you could register a function for on change, which basically sends HTP request on every keystroke 22 00:01:36,160 --> 00:01:37,570 would work here. 23 00:01:37,570 --> 00:01:40,260 Eivor I'm updating the saved value and every keystroke. 24 00:01:40,270 --> 00:01:43,900 And instead, what we can do is we can use use effect here. 25 00:01:44,730 --> 00:01:45,600 Added here. 26 00:01:46,640 --> 00:01:54,230 And Pazin, a function that should make that HTTP request and we simply specify entered filter as a 27 00:01:54,230 --> 00:01:58,550 dependency, and this means this function will execute whenever entered filter changed. 28 00:01:58,850 --> 00:02:00,130 So it's having the same result. 29 00:02:00,140 --> 00:02:05,060 But in my opinion, it's a bit more elegant because we're really embracing the ideal folksier. 30 00:02:05,330 --> 00:02:11,420 We're splitting our logic dysfunction only updates what the user entered or only updates to state where 31 00:02:11,420 --> 00:02:17,510 we store what the user entered and then use effect will automatically execute thereafter and do whatever 32 00:02:17,510 --> 00:02:19,190 we want to do for every change. 33 00:02:19,670 --> 00:02:21,860 So here I want to send a request. 34 00:02:22,850 --> 00:02:27,410 So I'll go to Ingredients Jass and basically fetch the logic I have in here. 35 00:02:31,430 --> 00:02:37,520 For fetching the requests, let's grab that, copy it and add here into use fact. 36 00:02:38,700 --> 00:02:42,810 You are l'Est, the same, transformation's the same, but of course, in the end, I don't call set 37 00:02:42,810 --> 00:02:48,480 yuzu ingredients, but instead I want to trigger something in ingredients Jass right. 38 00:02:48,480 --> 00:02:50,520 Because that is where we manage our ingredients. 39 00:02:50,760 --> 00:02:53,710 That is where we also use the search component. 40 00:02:53,970 --> 00:02:58,840 So in the end, we should establish a connection between search and this ingredients component to update 41 00:02:58,840 --> 00:03:02,390 the ingredients here whenever we fetched new ingredients in search. 42 00:03:02,730 --> 00:03:06,180 Let's say now, of course, typically for that, we would use props. 43 00:03:07,190 --> 00:03:13,040 So we can specify, let's say props onload ingredients name is totally up to you, Caldas as a function 44 00:03:13,190 --> 00:03:16,160 and forward our loaded ingredients like this. 45 00:03:16,580 --> 00:03:21,950 So all the ingredients is now a function, I expect on my search components. 46 00:03:21,950 --> 00:03:28,430 So in the ingredients component, we have to specify this prop on the search component and there forward 47 00:03:28,430 --> 00:03:33,930 a pointer at a function that should execute when all those ingredients is called in the search component. 48 00:03:34,730 --> 00:03:36,100 We have no such function yet. 49 00:03:36,110 --> 00:03:37,310 So let me add a new one. 50 00:03:37,310 --> 00:03:44,060 Maybe here at the very top, all named is filtered ingredients handler or whatever you want to call 51 00:03:44,060 --> 00:03:44,230 it. 52 00:03:44,840 --> 00:03:45,800 We get our. 53 00:03:47,030 --> 00:03:53,480 Filtered ingredients or whatever you want to call that as an argument, and the idea here is simply 54 00:03:53,480 --> 00:03:58,850 that we call set user ingredients we set as equal to our filtered ingredients because these should already 55 00:03:58,850 --> 00:03:59,930 be in the right format. 56 00:04:00,140 --> 00:04:06,710 So a very simple function then passing a pointer at this function to onload ingredients on the search 57 00:04:06,710 --> 00:04:10,540 component so that we can call this function from inside the search component. 58 00:04:11,000 --> 00:04:14,990 Now, back in the search component, we're calling this now with debt. 59 00:04:15,590 --> 00:04:18,709 We have a fact that runs whatever entered filter changes. 60 00:04:18,709 --> 00:04:21,290 But now here we're getting a warning in the end. 61 00:04:21,320 --> 00:04:26,540 The problem is that we're relying on props here, but we haven't specified them as a dependency. 62 00:04:26,540 --> 00:04:32,060 And that means that if props changed, does components, will we render but does affect won't rerun? 63 00:04:32,060 --> 00:04:36,830 Because we haven't informed the effect about the fact that props are a dependency. 64 00:04:37,420 --> 00:04:40,370 You might say, well, I'm only pointing at a function here. 65 00:04:40,370 --> 00:04:42,370 That function shouldn't change. 66 00:04:42,380 --> 00:04:46,400 So actually that shouldn't rerun if props change. 67 00:04:46,820 --> 00:04:49,720 But you should never cheat regarding your dependencies. 68 00:04:50,060 --> 00:04:55,790 It's a good practice to always be clear about all dependencies you have in here perhaps is a dependency, 69 00:04:55,790 --> 00:05:02,900 but still we will have a problem with that now does affect will rerun whenever props change, that basically 70 00:05:02,900 --> 00:05:03,590 is the case. 71 00:05:03,800 --> 00:05:09,620 Whenever anything passed to this component here changes or whenever anything in the parent component 72 00:05:09,620 --> 00:05:11,510 changes, that's also not what we want. 73 00:05:11,870 --> 00:05:15,380 We only want to rerun this function if onload ingredients. 74 00:05:15,500 --> 00:05:18,650 So if dysfunction, we're pointing it if that's changed. 75 00:05:19,680 --> 00:05:26,880 And for that, we can use another modern JavaScript syntax, maybe right here at the very top, we saw 76 00:05:26,880 --> 00:05:27,980 a way to structuring. 77 00:05:28,350 --> 00:05:33,590 There always is a concept called object structuring works in a very similar way. 78 00:05:33,900 --> 00:05:37,110 We have curly braces in this case on the left side of the equals sign. 79 00:05:37,230 --> 00:05:42,360 On the right side, we have the object which we want to destructor or from which we want to extract 80 00:05:42,360 --> 00:05:43,100 properties. 81 00:05:43,560 --> 00:05:50,400 And then here, between the curly braces on the left side, you specify the names of the keys in that 82 00:05:50,400 --> 00:05:54,640 object, which you want to extract, in which you want to store and separate variables. 83 00:05:54,810 --> 00:05:57,810 So in my case here, that would be onload ingredients. 84 00:05:57,840 --> 00:06:00,570 I know that this will exist as a key and props. 85 00:06:00,960 --> 00:06:06,570 I'm calling it here and now I'm simply pulling that out and storing it in a separate onload ingredients 86 00:06:06,570 --> 00:06:07,180 constant. 87 00:06:07,860 --> 00:06:09,480 So this is now a separate constant. 88 00:06:09,750 --> 00:06:14,970 And here we can just call onload ingredients and we can specify all loading regions as a dependency 89 00:06:14,970 --> 00:06:15,630 now and now. 90 00:06:15,630 --> 00:06:19,780 This will only rerun this effect if exactly this value changed. 91 00:06:19,920 --> 00:06:27,120 So if anything else and props changed, this will not rerun only if dysfunction changed or if the entered 92 00:06:27,120 --> 00:06:34,110 filter changed in these cases will send the request here and this request will get our data, then call 93 00:06:34,110 --> 00:06:35,460 onload ingredients in the end. 94 00:06:35,730 --> 00:06:37,920 And that should set our ingredients here. 95 00:06:39,470 --> 00:06:46,220 Now, a request right now, however, is not taking the entered filter into account, it's fetching 96 00:06:46,220 --> 00:06:46,940 all ingredients. 97 00:06:46,950 --> 00:06:49,900 Of course, it should fetch filtered ingredients instead. 98 00:06:50,690 --> 00:06:53,750 Thankfully, Firebase supports filtering. 99 00:06:54,320 --> 00:06:58,670 We can append some very Perens which are stored in a separate variable here. 100 00:06:59,120 --> 00:07:00,650 To the end of this, you are El. 101 00:07:01,660 --> 00:07:06,700 And I want to have different groups depending on where we entered something or not, so if entered filter 102 00:07:06,700 --> 00:07:11,180 length is equal to zero, then my career will be nothing. 103 00:07:11,200 --> 00:07:13,050 I'll not add any query parameters. 104 00:07:13,060 --> 00:07:14,230 So it's just an empty string. 105 00:07:14,620 --> 00:07:18,450 Otherwise it will be a string for which I use back ticks here. 106 00:07:18,460 --> 00:07:24,310 So these are not single quotes, but back ticks so that we can use string interpolation to dynamically 107 00:07:24,310 --> 00:07:25,630 inject values here. 108 00:07:26,320 --> 00:07:34,990 And then you should add questionmark order by written like that, equal double quotes opening and closing 109 00:07:35,410 --> 00:07:38,530 and between the double quotes, the field for which one to falter. 110 00:07:38,530 --> 00:07:40,240 In our case, that's the title field. 111 00:07:41,190 --> 00:07:48,480 Then ampersand equal to like that, equal sign, double quotes opening and closing. 112 00:07:48,600 --> 00:07:53,730 And now with string interpellation, which is done with Dollar Sign and then opening and closing Curly 113 00:07:53,730 --> 00:07:56,520 Brace, Disvalue entered and entered filter. 114 00:07:57,560 --> 00:08:03,320 This sets up query, which is never an empty string or this string here, and this is simply a syntax, 115 00:08:03,530 --> 00:08:09,320 a combination of query Purim's understood by Firebase to in the end, filter the title field for the 116 00:08:09,320 --> 00:08:10,580 value entered here. 117 00:08:11,060 --> 00:08:18,800 We have to append does at the end of our request here so we can simply add plus Creary plus query here 118 00:08:18,800 --> 00:08:22,610 in the end and that's ibut an empty string or that valid query set up. 119 00:08:23,600 --> 00:08:27,800 Now to make this work we need to all make a tiny adjustment here on Firebase. 120 00:08:27,950 --> 00:08:29,760 Go to rules in your database. 121 00:08:30,200 --> 00:08:36,860 Now we need to add an entry here to unlock filtering and double quotes here after it is read right thing 122 00:08:37,400 --> 00:08:39,530 and there add ingredients. 123 00:08:39,860 --> 00:08:46,760 So basically the name you have as a node here, you are sending your data to ingredients and then the 124 00:08:46,760 --> 00:08:53,600 value is no object yet and you end with opening and closing curly braces and then they're add another 125 00:08:53,600 --> 00:08:58,040 string with double quotes, dot index on which is a command understood by Firebase. 126 00:08:58,340 --> 00:09:05,000 And then this is an array again with a string value in there, which is basically the field name by 127 00:09:05,000 --> 00:09:06,310 which you want to be able to filter. 128 00:09:07,190 --> 00:09:14,000 So you need to add this setup here to your firebase rules with the setup we can filter for the title. 129 00:09:14,370 --> 00:09:16,730 Now we can send requests here. 130 00:09:17,590 --> 00:09:23,530 Now, a request should be sent whenever we type something here, so let's now save that go back to wrap 131 00:09:24,190 --> 00:09:27,640 and you see, oh, we seem to be in an infinite loop again here. 132 00:09:28,610 --> 00:09:34,640 So to leave it, let's comment out on those ingredients and safeties and reload what's causing this 133 00:09:34,640 --> 00:09:35,240 infinite loop? 13904

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