How to share state between layout components and children server components
Answered
Philippine Crocodile posted this in #help-forum
Philippine CrocodileOP
How to share state between layout components and children server components in next.js 14 App Router?
Answered by joulev
they are rendered independently, so no you cant share data between them.
but you can simply run the same query that you run in the layout, in the child server component too. add [React.cache](https://nextjs.org/docs/app/building-your-application/caching#react-cache-function) to ensure the query only runs once despite being called multiple times.
but you can simply run the same query that you run in the layout, in the child server component too. add [React.cache](https://nextjs.org/docs/app/building-your-application/caching#react-cache-function) to ensure the query only runs once despite being called multiple times.
5 Replies
@Philippine Crocodile How to share state between layout components and children server components in next.js 14 App Router?
they are rendered independently, so no you cant share data between them.
but you can simply run the same query that you run in the layout, in the child server component too. add [React.cache](https://nextjs.org/docs/app/building-your-application/caching#react-cache-function) to ensure the query only runs once despite being called multiple times.
but you can simply run the same query that you run in the layout, in the child server component too. add [React.cache](https://nextjs.org/docs/app/building-your-application/caching#react-cache-function) to ensure the query only runs once despite being called multiple times.
Answer
Philippine CrocodileOP
Thanks
is it possible to revalidate, so every one hour I can get refreshed data?
Philippine CrocodileOP
👍