All language subtitles for 005 Reusing Logic Inside A Component_Downloadly.ir_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

Original subtitles

So we learned about head and, typically,

you wanna set up your head content

in every page and also in every if branch inside of a page.

Because you have very specific titles and contents

for those different scenarios.

Now, here in the slug page, for example,

we definitely want to set our own title,

and our own description, but maybe we wanna use

the same title and description

for all the different if cases then.

So, we want to reuse that and not copy it manually

into all those different cases.

We could copy it but that's, of course, annoying.

Now, reusing here is simple,

we don't need any special Next.js concept.

We can use a standard React.js approach.

Instead of copy and pasting it,

we cut it from down there, and we set it up once right

at the beginning of this component render function.

So, here before I have my first if check,

so before we render something the first time,

so to say, I create a new constant pageHeadData,

or whatever you want to name it.

And that contains my head section.

Now, since I rely on numMonth and numYear here

we might want to extract this first.

So, I'll cut that here and move this

in front of this pageHeadData part here.

And then, we can just include pageHeadData

in all our return statements.

So for example, here, I then wrap this into a fragment

because I now want to add an adjacent JSX element.

I wanna also include my pageHeadData

and output the content of this constant dynamically

in this returned JSX code and the content

of this constant, of course, is this JSX code.

And we can now do this in all our return statements.

So, also here, and here, and also

in the final return statement here.

So, that would be a standard React way

of reusing some logic and if we do that,

if I reload, I get an error

that I cannot read property 0 of undefined.

And the problem is that I'm accessing my filtered data here

and the filtered data might be empty, of course,

or it actually will be when the page renders the first time

because I explained that use router works such

that it runs when the page was first rendered

and if it doesn't have the path parameter values,

at this point, it then runs again

and has access to them thereafter

but not at the beginning.

And therefore, actually, I want to move

that filtered data part after the if loaded events part

that was correct, and I want to set up my pageHeadData there

after therefore, so below here,

but I will remove const here,

and instead create pageHeadData as a variable here

and just assign a different content at the beginning.

So, here it still holds the head element

but I'll have a different description.

So, I'll copy the title and my meta content here.

But the description here is a list

of filtered events, something like this.

So, now, we changed the pageHeadData

inside of this component function,

depending on whether we have data or not.

And, with that, if we save this and reload,

this does load and now, if I inspected the page source here,

we see that we do have that title

and that we do have that description here.

So, that's how we can reuse

the head data inside of a component,

if we have different return statements

and therefore different pieces of JSX code

that might be rendered by that component.

But that's not the only way of reuse that which we have.

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