All language subtitles for 003 Creating a Wrapper Component_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
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

Original subtitles

So, let me introduce the solution to you.

What if we would use a dirty little trick?

Here in my components folder,

I'll add a new sub folder helpers.

I'll name it helpers because debt best describes

which kind of component I'm going to add.

I'm going to add a wrapper

component. I'll name the file wrapper JS.

And in there, I won't even import React

because I'm not going to write any JSX code in there.

Instead, I'll just create my wrapper component,

get props and have my function body,

and export this wrapper.

And now you might be wondering what I'm going to do here

if I'm not writing any JSX code.

Well, I'll just return props.children.

Remember the children prop holds all the content

you're passing between the opening and closing tag

off your custom component.

Now it is valid in a component to just return that content

which you got between the opening and closing text.

And now I can import my wrapper,

for example, here in add user,

I can import wrapper from helpers, wrapper.

And I can use it as a regular react component.

So I can go down there and replace my div,

which has no other meaning

than fulfilling this JSX requirement with my wrapper.

So I'm using my rapper component here

and just to make this really clear again,

this is basically an empty component.

Everything it does is that it returns props children.

But this is enough to fulfill this requirement JSX has.

If I save this my application still works just fine.

And it works just fine because an add user,

we have a wrapping element.

Sure, it's an element which won't render

anything to the dom, but the requirement

is not that there must be one root component

being rendered to the dom.

The requirement just is, that there must be one root element

that you return or that you store in a constant or variable.

And that's what we're doing here.

We have one root element the wrapper,

and what we pass into that wrapper,

may be adjacent, that is okay as I explained.

Now of course all that content is taken

and just returned here, but that's also okay

because in this return statement,

I technically still only returned one thing,

I return the value in props children.

And this can be tough to wrap your head around

but this is just a technical requirement of JavaScript

around which we're working here.

I just work around that requirement

by returning one thing here,

and one thing here.

And of course what we get here in props children

will be that adjacent content,

but that will not be a problem

because I never directly returned that in my code.

And this will therefore work just fine.

This will not cause any errors as you can clearly tell.

Now that's a nice little trick for solving this problem.

Because if we now have a look at the elements tab

and therefore at the dom, which is actually being rendered,

we see that if I inspect my add form component,

here's my form,

we see there is a div around it,

but that's just this card div.

But what we also see is if I click Add user,

that this modal div is being added.

But around that, we do have a wrapping div,

but this is actually the div coming from the app component

where I also have the wrapping div.

This is not coming from inside the add user component.

Instead from inside there,

nothing is being rendered into real dom.

We got the card and above that, nothing.

Because again, this div which is above it

is coming from the app component.

And that is of course pretty sweet.

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