I want share any data for each request, so I create object with these data in rootLayout
export interface IProps {
children: React.ReactNode;
data: any;
}
export default function RootLayout(props: IProps) {
const {children} = props;
props.data = {item: "hello"} // I know this is bad (only for test)
return children;
}
Now I need access data in page or layout on server side.
export default function Layout(props: IProps) {
const {children, data} = props;
console.log("Data", data);
return children;
}
Is there any way for share data per request or can I extend props for all children of root layout (on server)?
2
Answers
Okey here is exactly my issue:
RootLayout.tsx (create instance per request)
layout.tsx (child server component)
page.tsx
All of these usages of nodeInstance has one instance per request. But this solution doesnt work.
answered here:
also if you want to share data between server components base on nextjs document you can call your api with fetch anywhere you want: