-
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Thank you for your feedback. I hope my answer can solve your problem
// src/routes/layout.tsx
import { RuntimeContext } from '@modern-js/runtime';
type InitialData = {
message: string;
}
export const init = (context: RuntimeContext): InitialData => {
return {
message: 'Hello World',
};
}; // src/routes/page.tsx
import { useRuntimeContext } from '@modern-js/runtime;
export default () => {
const context = useRuntimeContext();
const { message } = context.initialData as InitialData;
return <div>{message}</div>;
}; Additionally, if you want to request and manage data, the most recommended solution is data-fetch, rather than |
Beta Was this translation helpful? Give feedback.
Thank you for your feedback. I hope my answer can solve your problem
error instanceof Error
,isRouteErrorResponse(error)
.runtimeContext
, which should be a mistake. Thanks for your feedback. I will fix it.init
function is a conventional API; the framework will call theinit
function and inject theruntimeContext
.