All language subtitles for 009 How React Works & Understanding 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,180 --> 00:00:06,240 Now with the project cleaned up, let's explore React 2 00:00:06,240 --> 00:00:09,200 and let's write our own React code. 3 00:00:09,200 --> 00:00:12,470 Currently, we got two Java script files here, 4 00:00:12,470 --> 00:00:14,890 index JS and app JS. 5 00:00:14,890 --> 00:00:18,990 The index JS file will be the starting point 6 00:00:18,990 --> 00:00:20,660 of our React application. 7 00:00:20,660 --> 00:00:22,200 The code written in here 8 00:00:22,200 --> 00:00:23,860 will be the first code 9 00:00:23,860 --> 00:00:26,403 that will be executed in the browser 10 00:00:26,403 --> 00:00:30,580 when we load our project in the browser. 11 00:00:30,580 --> 00:00:34,300 So what we see here in the browser is the result 12 00:00:34,300 --> 00:00:38,500 of this code line here, executing in the end. 13 00:00:38,500 --> 00:00:41,820 Now we don't fully understand this code line yet 14 00:00:41,820 --> 00:00:43,620 but what we do in this file 15 00:00:43,620 --> 00:00:46,580 is we're importing a couple of things. 16 00:00:46,580 --> 00:00:50,120 That is how in modern JavaScript 17 00:00:50,120 --> 00:00:53,430 support that by that build setup we have here 18 00:00:53,430 --> 00:00:55,970 supported by the NPM start script 19 00:00:55,970 --> 00:00:58,210 and what it does behind the scenes 20 00:00:58,210 --> 00:01:03,210 how we combine multiple files and how we import features 21 00:01:03,340 --> 00:01:08,220 like objects or functions from file A into file B. 22 00:01:08,220 --> 00:01:09,740 And here we are, for example 23 00:01:09,740 --> 00:01:14,740 importing the React Dom object from the React Dom library. 24 00:01:15,200 --> 00:01:17,570 So that's not object we created. 25 00:01:17,570 --> 00:01:20,420 That is an object created by the React team 26 00:01:20,420 --> 00:01:23,280 exposed in that React Dom library, 27 00:01:23,280 --> 00:01:25,060 which is part of our project 28 00:01:25,060 --> 00:01:28,003 because it's part of our dependencies here. 29 00:01:28,900 --> 00:01:30,200 Now on that object 30 00:01:30,200 --> 00:01:32,030 we call a render method 31 00:01:32,030 --> 00:01:33,570 and queued at render method. 32 00:01:33,570 --> 00:01:37,470 we pass this strange HTML code. 33 00:01:37,470 --> 00:01:41,410 Now this HTML in Java script syntax here 34 00:01:41,410 --> 00:01:43,500 only works because of that build step, 35 00:01:43,500 --> 00:01:44,630 as mentioned before 36 00:01:44,630 --> 00:01:46,690 and it's actually called JSX. 37 00:01:47,545 --> 00:01:48,378 This kind of code is called a J S X code. 38 00:01:50,825 --> 00:01:54,460 This HTML in Java script code. 39 00:01:54,460 --> 00:01:57,060 JSX is a special syntax 40 00:01:57,060 --> 00:01:59,430 which is not understood by the browser 41 00:01:59,430 --> 00:02:02,010 and which the offer is converted behind the scenes. 42 00:02:02,010 --> 00:02:05,570 But which is more convenient for us as a developer to write 43 00:02:05,570 --> 00:02:07,220 because working with React 44 00:02:07,220 --> 00:02:11,240 will be about building custom HTML elements, 45 00:02:11,240 --> 00:02:12,200 these components 46 00:02:12,200 --> 00:02:14,000 and combining them together. 47 00:02:14,000 --> 00:02:15,380 And that is way easier. 48 00:02:15,380 --> 00:02:18,620 If we can just write HTML code 49 00:02:18,620 --> 00:02:21,120 kind of in our JavaScript files 50 00:02:21,120 --> 00:02:23,930 to describe the desired output. 51 00:02:23,930 --> 00:02:25,686 So here we kind of create 52 00:02:25,686 --> 00:02:30,590 or we use our own HTML element, the app element 53 00:02:30,590 --> 00:02:34,020 which is actually imported from that app file. 54 00:02:34,020 --> 00:02:35,880 The file extension is missing here 55 00:02:35,880 --> 00:02:39,480 because for JavaScript files, it can be omitted. 56 00:02:39,480 --> 00:02:41,830 And the second argument to the render method 57 00:02:41,830 --> 00:02:45,730 in the end just tells React where this element 58 00:02:45,730 --> 00:02:47,993 should be rendered into real Dom. 59 00:02:49,470 --> 00:02:51,730 Now, here we are selecting an element by ID 60 00:02:51,730 --> 00:02:53,030 with an ID route 61 00:02:53,030 --> 00:02:54,160 and we can find this 62 00:02:54,160 --> 00:02:57,960 on the single page that is part of this project. 63 00:02:57,960 --> 00:03:00,160 We find it in the public folder. 64 00:03:00,160 --> 00:03:04,890 There we got a couple of images, but also one HTML file. 65 00:03:04,890 --> 00:03:07,710 That is the single HTML file 66 00:03:07,710 --> 00:03:10,160 that makes up this React application. 67 00:03:10,160 --> 00:03:11,590 Because I mentioned before 68 00:03:11,590 --> 00:03:12,830 you typically build 69 00:03:12,830 --> 00:03:16,190 these single page applications with React 70 00:03:16,190 --> 00:03:21,080 where only one HTML file is fetched from a server 71 00:03:21,080 --> 00:03:24,600 and then React takes over and controls the Dom 72 00:03:24,600 --> 00:03:27,120 and what's visible on the screen. 73 00:03:27,120 --> 00:03:30,120 Now in this index HTML file in the body section 74 00:03:30,120 --> 00:03:32,740 we got a div with an ID route. 75 00:03:32,740 --> 00:03:35,370 And that ID route should be look familiar. 76 00:03:35,370 --> 00:03:36,290 That is the div, 77 00:03:36,290 --> 00:03:37,590 which we in the end 78 00:03:37,590 --> 00:03:39,590 select with this document, 79 00:03:39,590 --> 00:03:42,940 get element by ID code snippet here. 80 00:03:42,940 --> 00:03:43,970 And therefore, in the end 81 00:03:43,970 --> 00:03:46,880 what we tell React with that line 82 00:03:46,880 --> 00:03:51,780 is that we want to render our app HTML element 83 00:03:51,780 --> 00:03:54,080 our custom HTML element, 84 00:03:54,080 --> 00:03:55,010 which is defined 85 00:03:55,010 --> 00:03:57,960 in this app JS file into this place 86 00:03:57,960 --> 00:04:01,750 into the place of this element with this route ID. 87 00:04:01,750 --> 00:04:05,160 So into the place of that div here in the end. 88 00:04:05,160 --> 00:04:06,963 That's what we're telling React. 89 00:04:08,390 --> 00:04:12,470 That's why if we visit our page and we inspect it. 90 00:04:12,470 --> 00:04:14,240 So we don't view the page source 91 00:04:14,240 --> 00:04:17,010 but we inspected with the Dev tools here. 92 00:04:17,010 --> 00:04:19,540 When we have a look at the rendered Dom here 93 00:04:19,540 --> 00:04:21,829 we see embodied that there is this div 94 00:04:21,829 --> 00:04:23,320 with an ID of a root. 95 00:04:23,320 --> 00:04:27,080 And in there we see our div with hello 96 00:04:27,080 --> 00:04:30,250 which is the content we defined an app JS, 97 00:04:30,250 --> 00:04:31,560 and that should make sense 98 00:04:31,560 --> 00:04:34,062 because it is the app thing, 99 00:04:34,062 --> 00:04:36,690 which we import from the app JS file, 100 00:04:36,690 --> 00:04:38,380 which we rendered here. 101 00:04:38,380 --> 00:04:40,870 Now let's take a closer look at this app thing. 102 00:04:40,870 --> 00:04:43,320 Then that is a function, 103 00:04:43,320 --> 00:04:45,030 a function which we export 104 00:04:45,030 --> 00:04:48,120 to make it available outside of this file. 105 00:04:48,120 --> 00:04:51,000 But in the end, just a standard function 106 00:04:51,000 --> 00:04:53,610 a standard JavaScript function. 107 00:04:53,610 --> 00:04:54,991 The only special thing 108 00:04:54,991 --> 00:04:59,991 about that function is that it returns such JSX code. 109 00:05:00,410 --> 00:05:03,900 So there's HTML in JavaScript code. 110 00:05:03,900 --> 00:05:06,170 That's the only special thing. 111 00:05:06,170 --> 00:05:09,530 Other than that it's a regular JavaScript function. 112 00:05:09,530 --> 00:05:11,390 And that is super important. 113 00:05:11,390 --> 00:05:16,120 What we have here is a so-called React component. 114 00:05:16,120 --> 00:05:19,060 We can use it like an HTML element 115 00:05:19,060 --> 00:05:21,520 as we're doing it here in, in index JS 116 00:05:21,520 --> 00:05:24,510 but it's of course not an HTML element. 117 00:05:24,510 --> 00:05:25,920 the browser would know, 118 00:05:25,920 --> 00:05:27,610 but one defined by us 119 00:05:27,610 --> 00:05:30,150 the developers of this project. 120 00:05:30,150 --> 00:05:33,640 Now this component, as it's called in Reacts world 121 00:05:33,640 --> 00:05:35,460 this custom HTML element, 122 00:05:35,460 --> 00:05:37,530 is in the end just a function. 123 00:05:37,530 --> 00:05:38,363 A function 124 00:05:38,363 --> 00:05:39,770 which is to defined and exported 125 00:05:39,770 --> 00:05:43,810 and specifically a function that returns JSX. 126 00:05:43,810 --> 00:05:45,090 That's important. 127 00:05:45,090 --> 00:05:46,050 A component. 128 00:05:46,050 --> 00:05:47,760 so a function that should act 129 00:05:47,760 --> 00:05:51,670 as a component and be usable as a component by React 130 00:05:51,670 --> 00:05:53,510 must return something 131 00:05:53,510 --> 00:05:56,200 that can be rendered in the browser. 132 00:05:56,200 --> 00:05:58,240 That could be text. 133 00:05:58,240 --> 00:06:00,230 It could be a couple of other things, 134 00:06:00,230 --> 00:06:05,230 but it can and most typically will be HTML code as well. 135 00:06:05,500 --> 00:06:07,660 So this JSX code. 136 00:06:07,660 --> 00:06:09,050 And what's interesting 137 00:06:09,050 --> 00:06:10,210 is that in the browser, 138 00:06:10,210 --> 00:06:11,879 if we have a look at the Dom again 139 00:06:11,879 --> 00:06:15,360 we don't see our app element anywhere here. 140 00:06:15,360 --> 00:06:19,150 We don't see an HTML tag called app. 141 00:06:19,150 --> 00:06:22,810 Instead, we just see the content of our component here 142 00:06:22,810 --> 00:06:26,030 this div with hello as a text, 143 00:06:26,030 --> 00:06:28,550 because these custom elements, 144 00:06:28,550 --> 00:06:30,530 these are not known by the browser. 145 00:06:30,530 --> 00:06:34,330 We just write this code in our React application. 146 00:06:34,330 --> 00:06:37,000 And then when it runs in the browser, 147 00:06:37,000 --> 00:06:39,950 React will not render these custom elements, 148 00:06:39,950 --> 00:06:42,210 which wouldn't tell the browser anything, 149 00:06:42,210 --> 00:06:44,450 but instead it will render the content 150 00:06:44,450 --> 00:06:47,080 returned by these custom elements. 151 00:06:47,080 --> 00:06:50,260 And that's how these React components work 152 00:06:50,260 --> 00:06:51,093 in a nutshell. 153 00:06:51,093 --> 00:06:53,740 That is already one very important 154 00:06:53,740 --> 00:06:55,820 first piece of knowledge here 155 00:06:55,820 --> 00:06:57,700 that we have these React components 156 00:06:57,700 --> 00:06:59,970 which are functions returning JSX, 157 00:06:59,970 --> 00:07:03,270 which we can use to well tell, React, 158 00:07:03,270 --> 00:07:05,210 and therefore in the browser 159 00:07:05,210 --> 00:07:07,550 what should appear here on the screen. 160 00:07:07,550 --> 00:07:09,680 But of course, we typically don't do that 161 00:07:09,680 --> 00:07:12,570 with just one simple component 162 00:07:12,570 --> 00:07:15,420 that just returns a div of hello. 163 00:07:15,420 --> 00:07:16,970 Instead I mentioned before 164 00:07:16,970 --> 00:07:20,430 that I want to rebuild this basic first example 165 00:07:20,430 --> 00:07:22,160 with this delete button. 166 00:07:22,160 --> 00:07:23,850 And then there after 167 00:07:23,850 --> 00:07:26,420 dive into a little bit of a more complex project 168 00:07:26,420 --> 00:07:27,940 in a second step 169 00:07:27,940 --> 00:07:30,827 and therefore let's now work towards that first example 170 00:07:30,827 --> 00:07:31,954 with that delete button 171 00:07:31,954 --> 00:07:34,743 and that modal overlay. 12633

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