fix(server): make LayoutProps generic (#1592)

This commit is contained in:
Reed von Redwitz
2023-08-05 22:27:13 +02:00
committed by GitHub
parent cc0e2cb2ec
commit 1fb7f3bea9
5 changed files with 55 additions and 32 deletions
+5 -1
View File
@@ -1,8 +1,12 @@
import { LayoutProps } from "$fresh/server.ts";
import { LayoutState } from "./_middleware.ts";
export default function RootLayout({ Component }: LayoutProps) {
export default function RootLayout(
{ Component, state }: LayoutProps<unknown, LayoutState>,
) {
return (
<div class="root-layout">
{state.something === "it works" ? "it works\n" : "it doesn't work\n"}
<Component />
</div>
);
@@ -0,0 +1,13 @@
import { MiddlewareHandlerContext } from "$fresh/server.ts";
export type LayoutState = {
something: string;
};
export const handler = (
_req: Request,
ctx: MiddlewareHandlerContext<LayoutState>,
) => {
ctx.state.something = "it works";
return ctx.next();
};