All language subtitles for 012 Outputting Dynamic Data & Working with Expressions in JSX_en

af Afrikaans
sq Albanian
am Amharic
ar Arabic Download
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,280 --> 00:00:05,410 So now we know how to style our components. 2 00:00:05,410 --> 00:00:07,440 And again, we're definitely not done here, 3 00:00:07,440 --> 00:00:11,500 this is not the final look I wanna have. 4 00:00:11,500 --> 00:00:15,530 But before we dig deeper into tweaking the final look 5 00:00:15,530 --> 00:00:17,940 and adding more UI elements, 6 00:00:17,940 --> 00:00:21,810 let's think about one maybe obvious problem. 7 00:00:21,810 --> 00:00:24,910 We will probably not just have one expense 8 00:00:24,910 --> 00:00:26,870 and definitely not an expense 9 00:00:26,870 --> 00:00:29,610 where the data is just hard coded 10 00:00:29,610 --> 00:00:31,770 into the component as it is here. 11 00:00:31,770 --> 00:00:33,870 The date is hard coded here, 12 00:00:33,870 --> 00:00:36,920 the title is hard coded, the amount is hard coded 13 00:00:36,920 --> 00:00:39,040 and it's the only expense we have. 14 00:00:39,040 --> 00:00:41,950 In our final tracker we wanna have 15 00:00:41,950 --> 00:00:45,380 an unlimited amount of expenses if we want to. 16 00:00:45,380 --> 00:00:49,340 We want to have multiple expense item components in action. 17 00:00:49,340 --> 00:00:50,223 And after all 18 00:00:50,223 --> 00:00:55,040 that is one of the core ideas behind components. 19 00:00:55,040 --> 00:00:57,530 It's not just a separation of concerns, 20 00:00:57,530 --> 00:01:00,840 it's also there reusability. 21 00:01:00,840 --> 00:01:02,900 We wanna define a component 22 00:01:02,900 --> 00:01:05,570 and its HTML code once 23 00:01:05,570 --> 00:01:09,110 and then we want to be able to reuse it. 24 00:01:09,110 --> 00:01:10,630 And at the moment 25 00:01:10,630 --> 00:01:12,233 we're not able to do that. 26 00:01:13,900 --> 00:01:17,130 Therefore, that will be the next problem we'll work on. 27 00:01:17,130 --> 00:01:19,250 But before we work on that 28 00:01:19,250 --> 00:01:22,450 there's another problem which we have to solve first. 29 00:01:22,450 --> 00:01:24,360 And that's something I just mentioned, 30 00:01:24,360 --> 00:01:29,360 that all that data is hard coded here in this JSX code. 31 00:01:29,610 --> 00:01:34,610 This is unrealistic, some data may be hard coded sometimes 32 00:01:34,650 --> 00:01:36,810 but here for an expense item, 33 00:01:36,810 --> 00:01:38,880 something like the date and the title 34 00:01:38,880 --> 00:01:42,880 and the amount would typically be dynamic, 35 00:01:42,880 --> 00:01:45,760 which means it's not hard coded in the HTML code. 36 00:01:45,760 --> 00:01:49,107 Instead we receive that data from somewhere, 37 00:01:49,107 --> 00:01:53,020 for example from the user who entered it into a form 38 00:01:53,020 --> 00:01:55,283 and we then output it dynamically. 39 00:01:56,310 --> 00:01:59,990 Now for the moment we don't have the capabilities yet 40 00:01:59,990 --> 00:02:01,770 to receive it from the user, 41 00:02:01,770 --> 00:02:04,570 but we can fake dynamic data 42 00:02:04,570 --> 00:02:06,530 by at least adding more 43 00:02:06,530 --> 00:02:10,460 than just HTML code to this component. 44 00:02:10,460 --> 00:02:12,990 Because after all, we must not forget 45 00:02:12,990 --> 00:02:16,490 that a component in React is just a function. 46 00:02:16,490 --> 00:02:19,040 And that earlier I mentioned 47 00:02:19,040 --> 00:02:22,800 that components are the combination of HTML, 48 00:02:22,800 --> 00:02:26,833 to some extent CSS and also JavaScript. 49 00:02:28,020 --> 00:02:30,700 Now we definitely see HTML in action. 50 00:02:30,700 --> 00:02:33,490 We also saw some CSS being added 51 00:02:33,490 --> 00:02:35,290 but where's the JavaScript? 52 00:02:35,290 --> 00:02:37,910 Other than that being a function. 53 00:02:37,910 --> 00:02:40,950 Well, let's add some JavaScript code in that function 54 00:02:40,950 --> 00:02:42,690 before we return. 55 00:02:42,690 --> 00:02:45,140 For example, let's add a constant, 56 00:02:45,140 --> 00:02:48,170 so a variable which may never change 57 00:02:48,170 --> 00:02:50,940 and in there let's store a date 58 00:02:50,940 --> 00:02:53,580 by using the built in date constructor 59 00:02:53,580 --> 00:02:56,470 which comes with JavaScript. 60 00:02:56,470 --> 00:02:58,300 Let's give this constant a name, 61 00:02:58,300 --> 00:03:02,330 for example expense date, sounds like a fitting name. 62 00:03:02,330 --> 00:03:07,000 And then let's maybe set an initial date value here 63 00:03:07,000 --> 00:03:09,903 which is the year 2021, 64 00:03:10,750 --> 00:03:12,320 March as a month. 65 00:03:12,320 --> 00:03:15,270 And since the month field here starts at zero, 66 00:03:15,270 --> 00:03:17,320 March has the number two 67 00:03:17,320 --> 00:03:19,493 and then there the 28th. 68 00:03:25,260 --> 00:03:27,760 This is how we can create such a date object 69 00:03:27,760 --> 00:03:30,450 and this, and that's really important to me 70 00:03:30,450 --> 00:03:33,570 is just regular JavaScript, 71 00:03:33,570 --> 00:03:36,063 has nothing to do with React. 72 00:03:36,940 --> 00:03:39,250 And we can and we typically do 73 00:03:39,250 --> 00:03:42,930 have JavaScript code like this in our components 74 00:03:42,930 --> 00:03:47,240 here just to create some dummy data later in the course 75 00:03:47,240 --> 00:03:49,520 and in your React applications 76 00:03:49,520 --> 00:03:51,350 that could be any kind of code. 77 00:03:51,350 --> 00:03:54,400 For example to send a HTTP request 78 00:03:54,400 --> 00:03:58,330 and fetch data from a database, to validate user input 79 00:03:58,330 --> 00:04:01,223 or to do any other kind of task. 80 00:04:02,240 --> 00:04:05,730 So here we have our expense date, 81 00:04:05,730 --> 00:04:08,180 we can also have our expense title here 82 00:04:08,180 --> 00:04:11,040 which is maybe car insurance. 83 00:04:11,040 --> 00:04:14,430 So a simple string stored in this constant 84 00:04:14,430 --> 00:04:17,120 and then our expense amount, 85 00:04:17,120 --> 00:04:20,360 which is let's say a number 294 86 00:04:20,360 --> 00:04:21,572 dot 67. 87 00:04:22,860 --> 00:04:24,810 So we have these three constants, 88 00:04:24,810 --> 00:04:26,630 regular JavaScript code. 89 00:04:26,630 --> 00:04:29,930 And we now wanna output these values here 90 00:04:29,930 --> 00:04:32,240 in this HTML code. 91 00:04:32,240 --> 00:04:34,410 And that is a typical task, 92 00:04:34,410 --> 00:04:38,390 typically you don't have data hard coded in HTML. 93 00:04:38,390 --> 00:04:41,240 Instead to output dynamic data 94 00:04:41,240 --> 00:04:44,410 you use a special syntax React gives you 95 00:04:44,410 --> 00:04:47,610 inside of these JSX code snippets. 96 00:04:47,610 --> 00:04:50,050 You can replace hard coded data 97 00:04:50,050 --> 00:04:54,210 with opening and closing curly braces. 98 00:04:54,210 --> 00:04:58,150 Single curly braces opening and closing. 99 00:04:58,150 --> 00:05:00,700 And the special thing about these curly braces 100 00:05:00,700 --> 00:05:03,140 inside of your JSX code snippets 101 00:05:03,140 --> 00:05:06,430 is that in these curly braces between them, 102 00:05:06,430 --> 00:05:10,143 you can run basic JavaScript expressions. 103 00:05:11,020 --> 00:05:12,720 For example, one plus one, 104 00:05:12,720 --> 00:05:14,780 you can execute something like this there 105 00:05:14,780 --> 00:05:17,620 and it's now the result of this expression 106 00:05:17,620 --> 00:05:20,620 which will be output on the screen. 107 00:05:20,620 --> 00:05:24,050 So if I run one plus one between curly braces here, 108 00:05:24,050 --> 00:05:24,993 we see two. 109 00:05:26,520 --> 00:05:28,280 We can also do something like 110 00:05:30,100 --> 00:05:31,940 math random here 111 00:05:31,940 --> 00:05:36,330 and generate a random number with the built in math object. 112 00:05:36,330 --> 00:05:37,780 And we see the number here 113 00:05:37,780 --> 00:05:39,000 and every time I reload 114 00:05:39,000 --> 00:05:41,160 I get a new number of course. 115 00:05:41,160 --> 00:05:43,490 Now that's something we can do. 116 00:05:43,490 --> 00:05:45,760 Now here. I don't wanna get a random number, 117 00:05:45,760 --> 00:05:47,650 I don't wanna add one plus one. 118 00:05:47,650 --> 00:05:51,660 Instead, I want to refer to the value stored 119 00:05:51,660 --> 00:05:53,240 in this constant. 120 00:05:53,240 --> 00:05:57,400 And therefore we can just repeat that constant name here. 121 00:05:57,400 --> 00:06:01,240 This is also a valid JavaScript expression 122 00:06:01,240 --> 00:06:05,140 just pointing at a variable or a constant. 123 00:06:05,140 --> 00:06:06,890 In this case a constant. 124 00:06:06,890 --> 00:06:09,570 And now JavaScript will extract the value 125 00:06:09,570 --> 00:06:11,180 stored in this constant 126 00:06:11,180 --> 00:06:13,520 and basically inject it here 127 00:06:13,520 --> 00:06:16,610 into this HTML code, so to say. 128 00:06:16,610 --> 00:06:18,330 So if I now save that, 129 00:06:18,330 --> 00:06:21,530 we again see car insurance here just like before 130 00:06:21,530 --> 00:06:25,130 but now it's not hard coded in the HTML code 131 00:06:25,130 --> 00:06:27,800 but instead here its output dynamically 132 00:06:27,800 --> 00:06:31,760 and the concrete value is taken from that constant. 133 00:06:31,760 --> 00:06:34,330 There of course it's still hard coded, 134 00:06:34,330 --> 00:06:36,313 but it's just a first step. 135 00:06:37,150 --> 00:06:39,570 Now we can do the same for the amount. 136 00:06:39,570 --> 00:06:41,870 So here after the dollar sign 137 00:06:41,870 --> 00:06:44,920 which I will leave hard coded for now. 138 00:06:44,920 --> 00:06:46,880 We can point at expense amount 139 00:06:48,120 --> 00:06:50,980 and for the date we can do something similar. 140 00:06:50,980 --> 00:06:53,690 Here we can output expense date, 141 00:06:53,690 --> 00:06:56,700 though for the date we have to keep in mind 142 00:06:56,700 --> 00:06:58,393 that it's a date object. 143 00:06:59,500 --> 00:07:02,520 And therefore if we try to save it like this 144 00:07:02,520 --> 00:07:04,810 it just breaks. 145 00:07:04,810 --> 00:07:07,270 Because this being a date object 146 00:07:07,270 --> 00:07:10,040 it can't be output as texts like this. 147 00:07:10,040 --> 00:07:13,970 However, we can call to ISO string for example, 148 00:07:13,970 --> 00:07:17,520 a built in method available on all date objects 149 00:07:17,520 --> 00:07:18,830 to output it as a string 150 00:07:18,830 --> 00:07:20,820 and now we see this at least. 151 00:07:20,820 --> 00:07:22,630 Not super readable 152 00:07:22,630 --> 00:07:24,430 but a first step. 153 00:07:24,430 --> 00:07:26,360 Now we will refine and fine tune 154 00:07:26,360 --> 00:07:29,020 the way this is being output later. 155 00:07:29,020 --> 00:07:30,680 For the moment we just achieved 156 00:07:30,680 --> 00:07:32,270 one important thing. 157 00:07:32,270 --> 00:07:34,450 We now no longer work 158 00:07:34,450 --> 00:07:38,030 with hard coded text in our HTML code 159 00:07:38,030 --> 00:07:41,760 but instead we have these dynamic placeholders, 160 00:07:41,760 --> 00:07:42,770 you could say. 161 00:07:42,770 --> 00:07:47,760 Where the concrete value can be the result of a calculation 162 00:07:47,760 --> 00:07:52,150 of a HTTP requests or as it is here at the moment 163 00:07:52,150 --> 00:07:56,140 the value stored in a constant or variable. 164 00:07:56,140 --> 00:07:58,860 And now with that out of the way 165 00:07:58,860 --> 00:08:00,810 we can move on 166 00:08:00,810 --> 00:08:03,130 and we can take a closer look 167 00:08:03,130 --> 00:08:07,690 at how we can make this expense item more reusable. 168 00:08:07,690 --> 00:08:10,150 So that it's not always the same data 169 00:08:10,150 --> 00:08:11,070 which we're outputting. 170 00:08:11,070 --> 00:08:14,060 And so that we can have multiple expense items 171 00:08:14,060 --> 00:08:18,393 based on one of the same component with different data. 12810

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