Is there a way to add <Head> in a Client component ?
Answered
Asari posted this in #help-forum
AsariOP
I don't want to use Server Components/Metadata stuff for this
Answered by Giant panda
Don't fight the convention. Use the way it's meant to be used.
9 Replies
Giant panda
Don't fight the convention. Use the way it's meant to be used.
Answer
Giant panda
Slightly related: https://nextjs-faq.com/metadata-client-components
@Asari don't. If you really really do I don't recommend having multiple titles render, update it manually
It's just a DOM element, you can do whatever you want to it. Do be careful though. Switch to jquery if you get tired of the syntax lmao
@Giant panda Don't fight the convention. Use the way it's meant to be used.
AsariOP
Not trying to, but tired of having to add server components only to use them for titles (I use Server Components for some pages but not for every page)
@qoobes <@407584626136186890> don't. If you really really do I don't recommend having multiple titles render, update it manually
AsariOP
Thanks for the tip @qoobes
Guess i'm gonna use serv components for this as it's meant.
@Asari I don't want to use Server Components/Metadata stuff for this
Yup, use server components. But if you really, really want to use client components for some reasons, then this work (don’t use unless you absolutely have to):
"use client";
import { useState } from "react";
export default function Page() {
const [title, setTitle] = useState("Hello World");
return (
<div>
{/* Yes, we simply put the <title> tag anywhere in the document. */}
<title>{title}</title>
<input value={title} onChange={e => setTitle(e.target.value)} />
</div>
);
}