All language subtitles for 022 Building Wrapper Components with props.children_en

af Afrikaans
ak Akan
sq Albanian
am Amharic
ar Arabic
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 Download
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:01,500 --> 00:00:05,080 Now, let's start with that card look. 2 00:00:05,080 --> 00:00:06,393 In case, it's not clear what I mean, 3 00:00:06,393 --> 00:00:08,947 I mean that look, which we all used earlier 4 00:00:08,947 --> 00:00:11,310 for the first demo project, 5 00:00:11,310 --> 00:00:13,950 where we simply have a nice white background 6 00:00:13,950 --> 00:00:15,385 and a slight drop shadow. 7 00:00:15,385 --> 00:00:18,860 And I'd like to have that for every meetup item. 8 00:00:18,860 --> 00:00:22,160 Now, we can solve this by adding a couple of CSS classes 9 00:00:22,160 --> 00:00:25,072 in the meetup item module CSS file, 10 00:00:25,072 --> 00:00:28,060 and then changing the look of our list item 11 00:00:28,060 --> 00:00:29,500 that would work. 12 00:00:29,500 --> 00:00:31,930 But this card look is so common 13 00:00:31,930 --> 00:00:33,860 that we may also want to use it 14 00:00:33,860 --> 00:00:37,132 in our components of this application. 15 00:00:37,132 --> 00:00:40,990 And we will actually use it in our components later. 16 00:00:40,990 --> 00:00:44,644 That's why I want to create a separate reusable component, 17 00:00:44,644 --> 00:00:49,607 which should act as a wrapper around our components, 18 00:00:49,607 --> 00:00:52,670 and just give those components some styling, 19 00:00:52,670 --> 00:00:54,190 which we then reuse. 20 00:00:54,190 --> 00:00:56,550 And for this in the components folder, 21 00:00:56,550 --> 00:01:00,210 I'll add a new sub folder, which I just want to name UI 22 00:01:01,340 --> 00:01:05,211 for user interface. The name is up to you, of course. 23 00:01:05,211 --> 00:01:06,070 In there, 24 00:01:06,070 --> 00:01:09,204 I want to store some general user interface components, 25 00:01:09,204 --> 00:01:11,940 which don't belong to a specific feature, 26 00:01:11,940 --> 00:01:15,910 but instead are used in different places of the app. 27 00:01:15,910 --> 00:01:18,370 And here, I'll add a card JS file 28 00:01:18,370 --> 00:01:22,983 and attached you find a card module CSS file, 29 00:01:24,075 --> 00:01:28,083 which you can simply add next to this card JS file. 30 00:01:29,150 --> 00:01:30,760 And then the car JS file, 31 00:01:30,760 --> 00:01:33,373 we'll now create a component as we did it before, 32 00:01:33,373 --> 00:01:37,238 simple functional component and export it of course. 33 00:01:37,238 --> 00:01:40,425 And we'll also import the styling, 34 00:01:40,425 --> 00:01:45,277 import classes from "./card.module CSS." 35 00:01:46,270 --> 00:01:50,670 And then in the component function, return a simple div, 36 00:01:50,670 --> 00:01:54,421 where we set the class name to classes.card. 37 00:01:54,421 --> 00:01:57,872 Now, the special thing about this component is, 38 00:01:57,872 --> 00:02:01,272 that this should now be the first custom component, 39 00:02:01,272 --> 00:02:06,203 which we can wrap around JSX content. 40 00:02:07,140 --> 00:02:10,470 Because the goal is to use this card components 41 00:02:10,470 --> 00:02:15,300 such that on a meetup item, inside of this list item, 42 00:02:15,300 --> 00:02:17,810 we can use card. 43 00:02:17,810 --> 00:02:21,440 And for this you need to add the import, 44 00:02:21,440 --> 00:02:26,110 so import card from going up one level diving into UI card. 45 00:02:27,520 --> 00:02:31,720 And we can wrap card around that JSX content 46 00:02:32,990 --> 00:02:35,350 so that we can use the card component like this. 47 00:02:35,350 --> 00:02:36,930 That's the goal. 48 00:02:36,930 --> 00:02:39,510 But at the moment, if you save all files, 49 00:02:39,510 --> 00:02:41,883 the result is that you don't see anything. 50 00:02:42,750 --> 00:02:44,840 And the reason is that at the moment, 51 00:02:44,840 --> 00:02:49,840 this card component simply swallows everything we wrap 52 00:02:49,855 --> 00:02:52,580 and throws it away, you could say. 53 00:02:52,580 --> 00:02:56,240 Because this card component just renders a div, 54 00:02:56,240 --> 00:02:58,020 and it doesn't know what it should do 55 00:02:58,020 --> 00:02:59,833 with any wrapped content. 56 00:03:00,780 --> 00:03:02,900 Now, it's such a common case, though, 57 00:03:02,900 --> 00:03:03,927 that you build components 58 00:03:03,927 --> 00:03:08,210 that should wrap itself around more JSX content. 59 00:03:08,210 --> 00:03:11,654 So you could say that you want to inject JSX content 60 00:03:11,654 --> 00:03:13,290 into this component. 61 00:03:13,290 --> 00:03:17,800 That react, of course has a solution for this case. 62 00:03:17,800 --> 00:03:21,330 And this solution, again, is related to props. 63 00:03:21,330 --> 00:03:23,460 We learned that we can pass props 64 00:03:23,460 --> 00:03:27,667 by adding attributes to an element, and that does work. 65 00:03:27,667 --> 00:03:30,096 But you can also add a special prop 66 00:03:30,096 --> 00:03:34,743 by passing content between the opening and closing text. 67 00:03:35,630 --> 00:03:39,440 And that content is then exposed under that special prop 68 00:03:39,440 --> 00:03:42,801 inside of that wrapping component. 69 00:03:42,801 --> 00:03:46,490 So here we accept the props parameter again. 70 00:03:46,490 --> 00:03:48,440 And then between the div text, 71 00:03:48,440 --> 00:03:52,203 I want to output props.children. 72 00:03:57,020 --> 00:03:58,918 The children prop is a special prop, 73 00:03:58,918 --> 00:04:02,700 which every component receives by default. 74 00:04:02,700 --> 00:04:05,620 And children always holds the content, 75 00:04:05,620 --> 00:04:08,240 which is passed between the opening 76 00:04:08,240 --> 00:04:10,230 and closing component text. 77 00:04:10,230 --> 00:04:11,776 So this JSX content, 78 00:04:11,776 --> 00:04:16,776 that is the value stored in that children prop in this case, 79 00:04:17,200 --> 00:04:20,403 when we use card in this component like this. 80 00:04:21,660 --> 00:04:25,490 And now I'm just outputting the value stored in children 81 00:04:25,490 --> 00:04:27,750 between these div text. 82 00:04:27,750 --> 00:04:30,132 And with that if we reload, 83 00:04:30,132 --> 00:04:32,690 we now have this slight card look 84 00:04:32,690 --> 00:04:35,110 and we see a drop shadow here. 85 00:04:35,110 --> 00:04:36,830 Since we take up too much width, 86 00:04:36,830 --> 00:04:40,420 we don't see it perfectly, but we can see it a bit. 87 00:04:40,420 --> 00:04:43,500 And if we inspect this in the div tools, 88 00:04:43,500 --> 00:04:45,880 we see that every meetup item here 89 00:04:46,890 --> 00:04:50,630 has this div with the card class. 90 00:04:50,630 --> 00:04:54,084 The name was transformed because of that CSS modules feature 91 00:04:54,084 --> 00:04:56,720 but it has that div with a card class 92 00:04:56,720 --> 00:05:00,567 wrapped around these other divs image content 93 00:05:00,567 --> 00:05:03,623 and actions inside of the list item. 94 00:05:05,120 --> 00:05:07,090 So that wrapping works, 95 00:05:07,090 --> 00:05:10,300 and that is another very important technique 96 00:05:10,300 --> 00:05:13,500 when it comes to composing user interfaces 97 00:05:13,500 --> 00:05:15,320 with react components 98 00:05:15,320 --> 00:05:18,410 and that's why we also cover it here. 99 00:05:18,410 --> 00:05:20,881 And we can now use this technique as well 100 00:05:20,881 --> 00:05:25,510 for setting up a general layout for this application 101 00:05:26,780 --> 00:05:30,052 because I'd like to have more white space 102 00:05:30,052 --> 00:05:32,520 around the content here. 103 00:05:32,520 --> 00:05:35,230 And for this, I'll go to the layout folder 104 00:05:35,230 --> 00:05:38,150 and add a layout component in there. 105 00:05:38,150 --> 00:05:41,397 Attached you also find a layout module CSS file, 106 00:05:41,397 --> 00:05:45,220 which you can add next to this JavaScript file. 107 00:05:45,220 --> 00:05:47,770 And then here in layout JS, 108 00:05:47,770 --> 00:05:52,270 we can create a layout component function 109 00:05:52,270 --> 00:05:54,953 and export it as a default. 110 00:05:56,440 --> 00:06:01,440 And import classes here from "./layout.module.css," 111 00:06:04,290 --> 00:06:08,400 and then in here, return our layout. 112 00:06:08,400 --> 00:06:13,380 And that could be a div with our main navigation, let's say. 113 00:06:13,380 --> 00:06:16,760 So from app JS, I'll cut main navigation 114 00:06:16,760 --> 00:06:18,913 and remove the imports there. 115 00:06:20,020 --> 00:06:23,660 And instead, in the layout component, I'll add that here. 116 00:06:23,660 --> 00:06:24,610 And therefore, of course, 117 00:06:24,610 --> 00:06:27,590 also add an import of main navigation 118 00:06:27,590 --> 00:06:30,790 from that main navigation JavaScript file, 119 00:06:30,790 --> 00:06:33,003 which is next to the layout file. 120 00:06:34,050 --> 00:06:38,950 And below that, we could use the regular main HTML element, 121 00:06:38,950 --> 00:06:43,277 and then use the layout component such that we wrap it 122 00:06:43,277 --> 00:06:47,390 around the actual JSX code that should be rendered. 123 00:06:47,390 --> 00:06:50,130 So we could say that in app JS, 124 00:06:50,130 --> 00:06:53,720 we want to wrap the content selected and rendered 125 00:06:53,720 --> 00:06:56,083 by the router with our layout. 126 00:06:57,420 --> 00:07:00,010 So here in app JS, 127 00:07:00,010 --> 00:07:04,547 we can import layout from going up 128 00:07:04,547 --> 00:07:09,547 diving into the components folder layout, layout. 129 00:07:10,820 --> 00:07:14,111 And instead of having this useless wrapping div, 130 00:07:14,111 --> 00:07:18,570 we could use our own layout component for wrapping here. 131 00:07:18,570 --> 00:07:22,180 And now this content here, the actual route contents, 132 00:07:22,180 --> 00:07:25,160 the page component that is being loaded, 133 00:07:25,160 --> 00:07:28,620 should be rendered inside of this main block. 134 00:07:28,620 --> 00:07:31,870 And we can again achieve this with props children. 135 00:07:31,870 --> 00:07:33,832 We can again accept props here, 136 00:07:33,832 --> 00:07:36,640 and then output props.children 137 00:07:36,640 --> 00:07:38,583 here inside of the main element. 138 00:07:39,700 --> 00:07:42,440 And that will then just forward that content, 139 00:07:42,440 --> 00:07:44,840 which is between our layout text. 140 00:07:44,840 --> 00:07:48,943 So this content here into that main element. 141 00:07:50,120 --> 00:07:51,920 Now here, we should also add 142 00:07:51,920 --> 00:07:56,388 a class name of classes.main for styling, 143 00:07:56,388 --> 00:07:59,010 and with that, if we save this, 144 00:07:59,010 --> 00:08:01,733 now we're utilizing this nice layout component 145 00:08:01,733 --> 00:08:04,348 for wrapping all our content. 146 00:08:04,348 --> 00:08:06,480 It's technically not required. 147 00:08:06,480 --> 00:08:08,921 We could have added the styling in another way too 148 00:08:08,921 --> 00:08:12,991 but it is another nice practice of this children concept, 149 00:08:12,991 --> 00:08:17,034 and it removes some extra code from our app component 150 00:08:17,034 --> 00:08:20,130 and make sure that this component can focus 151 00:08:20,130 --> 00:08:24,850 on one main thing, rendering the routing configuration. 152 00:08:24,850 --> 00:08:26,760 Because your components typically 153 00:08:26,760 --> 00:08:29,172 should be focused on one thing. 154 00:08:29,172 --> 00:08:32,062 And now we got a leaner app component, 155 00:08:32,062 --> 00:08:34,751 and we're again using props children 156 00:08:34,751 --> 00:08:37,722 to create this layout components here. 12393

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