Loading...
function Post({ post }) {
useEffect(() => {
document.title = post.title;
}, [post.title]);
return <article>{post.body}</article>;
}function Post({ post }) {
return (
<article>
<title>{post.title}</title>
<meta name="description" content={post.excerpt} />
{post.body}
</article>
);
}React hoists <title> and <meta> into <head>, so they also work in server-rendered HTML, where Effects never run.
<title>Hello {name}</title>, which gives the title several children and triggers a warning.<title>, <meta> and <link> render inside components, without third-party head libraries or document.title effects.<title> gets a single string, e.g. one template literal, not text mixed with JSX expressions.<link> tags set precedence so React hoists and orders them.For simple titles and meta tags, no. A library or framework API still helps with merging and overriding tags across nested routes.
Yes. With a precedence prop, React hoists the <link> to <head>, deduplicates it and waits for it to load before showing the content.