Next.js metadata vs React 19 title and meta components #75054
-
What to use and when, what is recommended? It would also be nice to have some note about this in the docs. Refs: |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 7 replies
-
Well... guess what! Next.js uses those internally. At least from looking at: return MetaFilter([
metadata.title !== null && metadata.title.absolute ? (
<title>{metadata.title.absolute}</title>
) : null, /* rest of implementation */ or export function ViewportMeta({ viewport }: { viewport: ResolvedViewport }) {
return MetaFilter([
<meta charSet="utf-8" />,
Meta({ name: 'viewport', content: resolveViewportLayout(viewport) }), /* rest of impl */ Not just that function but all of the functions ultimately used at: Which in turn is invoked by: https://github.com/vercel/next.js/blob/f140b2df6e4694fa0c12bf26261b06b0808ae8f8/packages/next/src/lib/metadata/metadata.tsx#L283C16-L283C30 And yada yada, yeah the metadata collected from the object exports, or So the Next.js set of utility functions, is an API to utilise these new React APIs, like, you focus on describing the metadata, and have it centralised at |
Beta Was this translation helpful? Give feedback.
-
@icyJoseph okay, what about the use with client components? If I use nextjs metadata in a page component with export const metadata: Metadata = {
title: 'Log in'
} If I simply use react <title>Log in</title> Seems like they don't work the same 🤔 |
Beta Was this translation helpful? Give feedback.
What I am trying to say here is that, you can just use the React APIs directly, because, Next.js implemented their metadata API, around them. It's just that their metadata API needs a server/build runtime, to generate the tags. And it has their benefits of you passing the metadata as objects, rather than having to map it all to JSX yourself. You can make API calls, to backend services, and hide that from the client, yada yada, introducing a layer of separation between what'll go in the body, and what stays in the head.
Next.js has been using React canary, where these API existed, for a very long time. So if using
title
directly, fits your use case, you might as well go for it. In other si…