I want to add a custom title to a client component based in the searchParams for the page but since it's a client component I cannot use the new metadata API in the page.tsx and I was thinking if there is some new way to add title to client component since head.tsx files are deprecated.
I've also tried using generateMetadata({ searchParams }) in the layout.tsx file where the component is used but the searchParams is undefined.
export async function generateMetadata({
searchParams
}: {
searchParams?: ReadonlyURLSearchParams;
}): Promise<Metadata> {
const username = searchParams?.get('username');
return { title: username ? `Viewing ${username}'s Profile` : 'Viewing Profile' };
}
but the searchParams parameter is always undefined. I also checked the docs to make sure I was the function appropriately and the docs also seems to be using searchParams in similar way.
Reference to docs: https://beta.nextjs.org/docs/api-reference/metadata#generatemetadata