All language subtitles for 002 Client Components_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
pl Polish
pt-BR Portuguese (Brazil)
pt Portuguese (Portugal)
pa Punjabi
qu Quechua
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

We've seen before, in the section on Rendering,

that if we need to use any

client-side functionality,

we need to add the "use client" directive

at the top of the file,

to mark this as a Client Component.

With this simple change, the error goes away.

But let's make sure we fully understand

what's going on here.

If we comment out the "use client" directive,

then this will be treated a Server Component,

and if we save, we get an error,

because we cannot use client-side functionality

in a Server Component.

Note that the error started when

we added the "onClick" handler.

If we remove this, then everything

works just fine,

because there's no longer any

client-side functionality,

and so this component can be

rendered only on the server.

Let's add a log statement here,

printing a message any time

this component is rendered,

just to remind ourselves of how rendering works.

By default, all our components

are Server Components,

meaning that they only render on the server.

There are no messages in the browser console.

With the "use client" directive however,

ShareLinkButton will be treated

as a Client Component.

This means that it will be rendered

both on the server and in the browser.

Let's see how this works in

terms of network requests.

I'll comment out "use client" again,

so we can start with the Server

Component behavior.

If we look at the Network requests,

when we open the page,

we know that the browser first

loads the HTML document.

And the Next.js server pre-renders

the HTML for all our components,

including ShareLinkButton.

Since it's currently a Server Component,

no JavaScript code will be sent to

the browser for this component.

So we see the button displayed on the page,

as rendered from this HTML code,

but we cannot have any actual functionality

attached to the button,

because the browser doesn't have any JavaScript

code associated with that component.

Now, let's turn it into a Client Component again,

and see what happens if we reload the page.

The first request will still be the HTML document,

and the ShareLinkButton was still

pre-rendered on the server.

However, since it's now a Client Component,

the browser will also receive

some JavaScript code,

that should include the function where

we log the "clicked" message.

This code contains the full

ShareLinkButton function.

After loading this JavaScript file,

the browser runs the component function,

rendering our component on the client-side.

In fact, in this function we

log a message to the console

saying "rendering".

And we do see that message printed

to the browser console,

proving that the browser is executing

our ShareLinkButton function.

So, the browser has the full

code for this component.

That's why we can now include

client-side functionality,

like an "onClick" handler for the button.

If we reload the page,

when we click the button we'll see that

our handler function is called,

and logs the "clicked" message.

Of course, it will be called again

whenever we click the button.

Now, the process of rendering

a component in the browser,

after it was already pre-rendered on the server,

is called "hydration".

It is a bit different from rendering

a component only in the browser,

like in traditional React

Single Page Applications,

because in this case we already

have some initial HTML,

generated by the server,

with all the elements for our

ShareLinkButton for example.

After loading and displaying that initial HTML,

the browser will then load the JavaScript code.

And it will execute our component function,

rendering a client-side version

of the same component.

It will be almost the same as the

HTML pre-rendered by the server,

but with an important difference:

the elements can have event handlers attached,

like the "handleClick" function associated

to the button "onClick" event.

So at this point the browser

needs to somehow merge

the elements already displayed on the page

from the initial HTML generated by the server,

with the elements rendered on the client side.

This is what the "hydration" process does.

The result will be

the same HTML elements pre-rendered by the server

but with the addition of event handlers,

and all the JavaScript code associated

with our component.

So at this point we have some

fully-interactive elements,

like a button that can actually do

something when the user clicks it.

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