Next.js Discord

Discord Forum

Page params to generateMetadata

Answered
Japanese Bobtail posted this in #help-forum
Open in Discord
Japanese BobtailOP
Hi there. Is it possible to get the result of "getPage" (server fetch) to the generateMetadata Function? Otherwise i've to call the api twice? Or doesn't matter because the fetch is caching?

export async function generateMetadata({ params }) {
const page = await getPage(params.slug);
if (!page) return false;

return {
title: page?.title '',
description: page?.excerpt
'',
};
}

export default async function Page({ params }) {
const page = await getPage(params.slug);
if (!page) return notFound();
//...
}


Thanks for help.
Answered by Ray
it should be fine if getPage is cached.

fetch requests are automatically memoized for the same data across generateMetadata, generateStaticParams, Layouts, Pages, and Server Components. React cache can be used if fetch is unavailable.
View full answer

4 Replies