Next.js Discord

Discord Forum

using metadata in client comps

Answered
Elite posted this in #help-forum
Open in Discord
so how could I call my client comp in a server comp?

Do i make the page.jsx a server comp?
Answered by Arinji
call it client component, and call it in the page
View full answer

45 Replies

so @Arinji what did u mean by
making a server component, calling your client component from it
like make my page.jsx a server comp?
Well actually its not a page.jsx only :D
every component is a server component
whichh can use the metadata
oh ye
unless you do "use client"/call a component from a client component its a server component
the metadata bubbles up to its parents till it reaches its final page or layout
ah so i shouldnt make my pages / layouts a 'use client'
just do the components inside of em unless the whole page is a use client?
so for my home layout and page
should I make the metadata inside of my layouts only?
but then if I set the title in the root layout as home, that would be used one everything till another layout overrides it right
@Elite ah so i shouldnt make my pages / layouts a `'use client'`
yea, ideally pages stay server components
@Elite so for my home layout and page should I make the metadata inside of my layouts only?
not needed, any server component can use metadata.. set them for the layout for stuff that wont change like titles etc
oh so in my compoonents i shoul set titles and suff (like home page, app page etc)
hm so in this page.jsx im using a onClick (for a back to top component)
I need the whole page to be a client comp either way
so im confused as to where I should set my meta data now
in the layout?
file looks like this
page.jsx is a client comp

should i set my title in layout.jsx to Home?
or somwhere else
so just make another component
call it client component, and call it in the page
Answer
its not an antipattern
ahh i see
and then i can use metadata in the page
@Arinji ideally dont make your page a client component
quick question kinda leading to this
so should I make everything components?
and then make my page just render that component?
what if its like just a few h1s and etc?
or should I only make components things I reuse
cause if its things I reuse then i can't keep my page.jsx as a server comp as none of that stuff is reused, I just render a ton of html stuff with useEffetcs, etc
stuff like client components can be localized the url folder itself :D
like this backtotop button
its a client comp, but I dont use anywhere else
where do I put the code for it
so then keep it in the route folder.. like if you have a route /test.. you have a folder called test right
so keep the component there
ahh i see
dont put it inside of components folder
yea, thats for like resuable stuff
thats my imo btw
not nextjs specified
nah nah it makes sense, always wondering
what does nextjs do?
np
@Elite what does nextjs do?
do whatever you want xD