Next.js Discord

Discord Forum

METADATA WITH CLIENT

Unanswered
CHEEMDA MAN posted this in #help-forum
Open in Discord
I want to know if I can use dynamic metadata in a client component/page in Next.js. I was trying to implement it, but it wasn't working well and showed an error that said it can't be used with 'use client.' Is there any way to make it work?

12 Replies

generateMetadata is only supported in Server Components, you cannot use that function to generate dynamic metadata from the client. https://nextjs.org/docs/app/api-reference/functions/generate-metadata
@CHEEMDA MAN Is there is any workaround??
No, what is your use case? Metadata must be set in a Server Component otherwise the intial HTML won't have the correct meta tags and your SEO will suffer for it.
If you want your metadata to update based on user interactions on the client you need to pass that data to the Server Component via URL search parameters or cookies.
Asian black bear
Also, pages really shouldn't be client components. You opt out of pretty much all the features that Next brings.
I can't see a single use case for a page being a client component vs just creating a client component that does what you were doing in that page and importing it.
@CHEEMDA MAN Passing data from component to page
Yeah you would use search parameters or cookies to do for client component to server component data
@Plague Yeah you would use search parameters or cookies to do for client component to server component data
Yea but ... Ok got it i was fetching data from api in the page now I'll send the data of parms in component then try to use meta data hope it will work