Transmit data from generateMetadata function
Answered
Mini Satin posted this in #help-forum
Mini SatinOP
Hey there, building a web page editor and i'm wondering if there's a way of transmitting data from
So the point here is that i need to fetch my page datas from my database to generate the metadatas.
I also need the page datas to render my page so right now i've got something that look like this :
Obviously there's nothing in props that permit me to retrieve the metadatas so i might split my model to avoid fetching the same data twice.
But there's still some common shared data like the author of the page etc... So be able to transmit the data from the
So if someone knows a way i would be glad to try it out !
generateMetadata
function ?So the point here is that i need to fetch my page datas from my database to generate the metadatas.
I also need the page datas to render my page so right now i've got something that look like this :
export const generateMetadata = async () => {
console.log("generating metadata");
const page = await getPage({ path: "/" });
return {
title: page.title,
//... other metadatas
};
};
export default async function Page(props) {
console.log("props", props);
const page = await getPage({ path: "/" });
return <Renderer page={page} />;
}
Obviously there's nothing in props that permit me to retrieve the metadatas so i might split my model to avoid fetching the same data twice.
But there's still some common shared data like the author of the page etc... So be able to transmit the data from the
generateMetadata
function could be convenient to me. Also because generateMetadata
always run before the rendering of the Page
component...So if someone knows a way i would be glad to try it out !
Answered by B33fb0n3
to avoid fetching the same data twice.wrap your
getPage
function inside a react cache and then even if you write the function twice, the function will only be executed once7 Replies
@Mini Satin Hey there, building a web page editor and i'm wondering if there's a way of transmitting data from `generateMetadata` function ?
So the point here is that i need to fetch my page datas from my database to generate the metadatas.
I also need the page datas to render my page so right now i've got something that look like this :
js
export const generateMetadata = async () => {
console.log("generating metadata");
const page = await getPage({ path: "/" });
return {
title: page.title,
//... other metadatas
};
};
export default async function Page(props) {
console.log("props", props);
const page = await getPage({ path: "/" });
return <Renderer page={page} />;
}
Obviously there's nothing in props that permit me to retrieve the metadatas so i might split my model to avoid fetching the same data twice.
But there's still some common shared data like the author of the page etc... So be able to transmit the data from the `generateMetadata` function could be convenient to me. Also because `generateMetadata` always run before the rendering of the `Page` component...
So if someone knows a way i would be glad to try it out !
to avoid fetching the same data twice.wrap your
getPage
function inside a react cache and then even if you write the function twice, the function will only be executed onceAnswer
happy to help
@B33fb0n3 happy to help
Australian Freshwater Crocodile
You get all the questions solved before we can even take a look ππ leave some for usππ
Jk
Jk
@Australian Freshwater Crocodile You get all the questions solved before we can even take a look ππ leave some for usππ
Jk
There are a lot of questions, that you (and others) answer before me. I skipping is lot in the last time π
I saw you in some threads. Keep up the good work π
I saw you in some threads. Keep up the good work π
@B33fb0n3 There are a lot of questions, that you (and others) answer before me. I skipping is lot in the last time π
I saw you in some threads. Keep up the good work π
Australian Freshwater Crocodile
I'm just kidding! I always read the threads to learn and your answers are on point so keep teaching us trough replies, I don't mind π haha. And thanks, I try!