All language subtitles for 015 Adding normal JavaScript Logic to Components_en

af Afrikaans
ak Akan
sq Albanian
am Amharic
ar Arabic Download
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
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,400 --> 00:00:04,700 Instructor: Now that we learned about props, 2 00:00:04,700 --> 00:00:09,466 we're basically done with our first custom component. 3 00:00:09,466 --> 00:00:12,933 This expense item component is now reusable 4 00:00:12,933 --> 00:00:16,065 and we can use this props concept to configure it 5 00:00:16,065 --> 00:00:19,033 differently every time that we're using it. 6 00:00:19,033 --> 00:00:19,333 differently every time that we're using it. 7 00:00:19,333 --> 00:00:22,833 So that the four times we're using ExpenseItem here 8 00:00:22,833 --> 00:00:26,766 we're also getting a different output four times. 9 00:00:26,766 --> 00:00:27,166 we're also getting a different output four times. 10 00:00:27,166 --> 00:00:29,033 I also just wanna emphasize again, 11 00:00:29,033 --> 00:00:32,900 that here we are indeed setting the values 12 00:00:32,900 --> 00:00:34,666 for the props dynamically 13 00:00:34,666 --> 00:00:37,866 with this single curly brace syntax 14 00:00:37,866 --> 00:00:38,166 with this single curly brace syntax 15 00:00:38,166 --> 00:00:41,200 but we could also just have a hard coded value 16 00:00:41,200 --> 00:00:42,733 like this here if that is what we needed. 17 00:00:42,733 --> 00:00:44,466 like this here if that is what we needed. 18 00:00:44,466 --> 00:00:48,566 So props are not limited to dynamically set values. 19 00:00:48,566 --> 00:00:49,600 We can do that, 20 00:00:49,600 --> 00:00:51,300 but we don't have to. 21 00:00:51,300 --> 00:00:54,333 The main idea behind props is always the same though. 22 00:00:54,333 --> 00:00:58,100 We wanna make sure that we can pass data into our components 23 00:00:58,100 --> 00:01:02,366 to make them configurable and reusable. 24 00:01:02,366 --> 00:01:05,833 Now let's continue working on that expense item component 25 00:01:05,833 --> 00:01:08,433 and let's continue working on that date. 26 00:01:08,433 --> 00:01:12,266 Because at the moment this is clearly not too pretty, 27 00:01:12,266 --> 00:01:15,166 not too human readable. 28 00:01:15,166 --> 00:01:15,333 not too human readable. 29 00:01:15,333 --> 00:01:17,666 And instead of showing it like this, 30 00:01:17,666 --> 00:01:21,633 I instead wanna have this calender like look 31 00:01:21,633 --> 00:01:24,366 which you see here in this preview. 32 00:01:24,366 --> 00:01:24,600 which you see here in this preview. 33 00:01:24,600 --> 00:01:27,833 I wanna have my date look like that. 34 00:01:27,833 --> 00:01:31,400 And therefore of course we need to change that HTML code, 35 00:01:31,400 --> 00:01:33,400 that JSX code 36 00:01:33,400 --> 00:01:33,466 that JSX code 37 00:01:33,466 --> 00:01:36,866 and I'm using these terms interchangeably as well. 38 00:01:36,866 --> 00:01:39,266 We need to change that which is responsible 39 00:01:39,266 --> 00:01:41,733 for outputting that date. 40 00:01:41,733 --> 00:01:46,200 And here to build such a calender look, 41 00:01:46,200 --> 00:01:49,000 we could say that inside of that main div 42 00:01:49,000 --> 00:01:53,000 which should hold the overall date element, 43 00:01:53,000 --> 00:01:57,900 we wanna have free individual divs like this, 44 00:01:57,900 --> 00:01:58,366 we wanna have free individual divs like this, 45 00:01:58,366 --> 00:02:02,066 where the top most div is responsible 46 00:02:02,066 --> 00:02:03,766 for outputting the month. 47 00:02:03,766 --> 00:02:07,200 The middle div is responsible for outputting the year 48 00:02:07,200 --> 00:02:10,666 and the bottom div then shows the date. 49 00:02:10,666 --> 00:02:13,400 That's something we could do. 50 00:02:13,400 --> 00:02:13,866 That's something we could do. 51 00:02:13,866 --> 00:02:18,000 And, of course, for that we wanna extract month, year 52 00:02:18,000 --> 00:02:20,733 and day from the incoming date. 53 00:02:20,733 --> 00:02:23,900 So from that date prop which we're setting. 54 00:02:23,900 --> 00:02:25,966 For that here for the month, 55 00:02:25,966 --> 00:02:31,500 we can output a value dynamically and access props.date, 56 00:02:31,500 --> 00:02:32,033 we can output a value dynamically and access props.date, 57 00:02:32,033 --> 00:02:33,533 and now what? 58 00:02:33,533 --> 00:02:37,100 How can we now output the month here? 59 00:02:37,100 --> 00:02:40,333 Well, we can use a built-in method which is 60 00:02:40,333 --> 00:02:41,200 Well, we can use a built-in method which is 61 00:02:41,200 --> 00:02:45,133 accessible on all date objects in JavaScript. 62 00:02:45,133 --> 00:02:51,266 We can call the toLocaleString method. 63 00:02:51,266 --> 00:02:53,966 Now this is not a React specific method. 64 00:02:53,966 --> 00:02:56,400 You can Google for JS toLocaleString 65 00:02:56,400 --> 00:03:00,100 to find an official article on this method. 66 00:03:00,100 --> 00:03:03,200 And this method simply helps you with outputting dates 67 00:03:03,200 --> 00:03:06,533 in human readable formats. 68 00:03:06,533 --> 00:03:06,866 in human readable formats. 69 00:03:06,866 --> 00:03:08,900 And you can simply call it and then pass 70 00:03:08,900 --> 00:03:11,333 in two arguments where the first argument 71 00:03:11,333 --> 00:03:16,033 is basically the language and here I'll use en-US 72 00:03:16,033 --> 00:03:18,100 to go with English. 73 00:03:18,100 --> 00:03:18,333 to go with English. 74 00:03:18,333 --> 00:03:20,733 And then the second argument is an object 75 00:03:20,733 --> 00:03:23,900 where you configure how specifically 76 00:03:23,900 --> 00:03:26,600 that date should be formatted. 77 00:03:26,600 --> 00:03:26,733 that date should be formatted. 78 00:03:26,733 --> 00:03:28,833 And here we got different options 79 00:03:28,833 --> 00:03:32,466 where you can find more details in that article 80 00:03:32,466 --> 00:03:34,633 which you can find. 81 00:03:34,633 --> 00:03:37,200 Here you can learn more about the various ways 82 00:03:37,200 --> 00:03:40,233 of configuring this and using this. 83 00:03:40,233 --> 00:03:40,633 of configuring this and using this. 84 00:03:40,633 --> 00:03:45,566 And here we can set month to long for example. 85 00:03:45,566 --> 00:03:47,833 That's one of the provided options 86 00:03:47,833 --> 00:03:50,600 or one of the supported options. 87 00:03:50,600 --> 00:03:53,366 And if we do that and save this, 88 00:03:53,366 --> 00:03:59,333 we see that August and March and June are being output here. 89 00:03:59,333 --> 00:03:59,366 we see that August and March and June are being output here. 90 00:03:59,366 --> 00:04:01,333 So that we got a human readable way 91 00:04:01,333 --> 00:04:03,800 of outputting that month. 92 00:04:03,800 --> 00:04:06,800 Now, doing that all in line here 93 00:04:06,800 --> 00:04:09,733 in that JSX code clearly works. 94 00:04:09,733 --> 00:04:10,966 As I mentioned earlier, 95 00:04:10,966 --> 00:04:13,300 when I introduced this syntax, 96 00:04:13,300 --> 00:04:17,700 you can have expressions like this between the curly braces 97 00:04:17,700 --> 00:04:20,100 but it is considered a better practice, 98 00:04:20,100 --> 00:04:22,266 and it leads to cleaner code. 99 00:04:22,266 --> 00:04:24,366 If you extract logic like that, 100 00:04:24,366 --> 00:04:27,166 and don't put it into your JSX code, 101 00:04:27,166 --> 00:04:30,500 but instead you create a separate helper variable 102 00:04:30,500 --> 00:04:32,533 or a constant. 103 00:04:32,533 --> 00:04:32,700 or a constant. 104 00:04:32,700 --> 00:04:34,366 Something like month here 105 00:04:34,366 --> 00:04:36,700 which simply holds that value. 106 00:04:36,700 --> 00:04:40,500 And then here between your curly braces in the JSX code 107 00:04:40,500 --> 00:04:45,166 you just point at that helper variable or a constant. 108 00:04:45,166 --> 00:04:45,600 you just point at that helper variable or a constant. 109 00:04:45,600 --> 00:04:48,866 By doing it like this you keep your JSX code lean 110 00:04:48,866 --> 00:04:52,833 and you have your more complex logic in the rest 111 00:04:52,833 --> 00:04:57,100 of this function so that this overall is easier to read. 112 00:04:57,100 --> 00:05:00,733 And now we can do something similar for the day 113 00:05:00,733 --> 00:05:01,733 and the year. 114 00:05:01,733 --> 00:05:09,633 For the day we can access props.date.toLocaleString en-US 115 00:05:09,633 --> 00:05:12,733 and then here passing a configuration where we say 116 00:05:12,733 --> 00:05:16,300 that we wanna format just the day 117 00:05:16,300 --> 00:05:19,600 and output it in a two digit format. 118 00:05:19,600 --> 00:05:22,400 And we can add a year helper constant 119 00:05:22,400 --> 00:05:25,466 where we access props.date 120 00:05:25,466 --> 00:05:25,600 where we access props.date 121 00:05:25,600 --> 00:05:28,666 and then actually just access get full year 122 00:05:28,666 --> 00:05:30,433 which is another built-in method 123 00:05:30,433 --> 00:05:35,000 which just extracts the year as a four digit number. 124 00:05:35,000 --> 00:05:39,366 And now we can use these helper constants 125 00:05:39,366 --> 00:05:45,266 to output their values like this in our JSX code. 126 00:05:45,266 --> 00:05:48,100 And if we do that and save that file, 127 00:05:48,100 --> 00:05:50,633 now we see the month, 128 00:05:50,633 --> 00:05:54,433 the year and also the day in the month. 129 00:05:54,433 --> 00:05:54,933 the year and also the day in the month. 130 00:05:54,933 --> 00:05:58,366 And that's the raw data which I wanna have here. 131 00:05:58,366 --> 00:06:01,766 Now, of course, one crucial thing is missing 132 00:06:01,766 --> 00:06:03,800 and that would be the styling. 133 00:06:03,800 --> 00:06:03,866 and that would be the styling. 134 00:06:03,866 --> 00:06:05,766 But before we add that, 135 00:06:05,766 --> 00:06:08,466 let's talk about splitting components. 10464

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