diff --git a/src/islands/Counter.tsx b/src/islands/Counter.tsx index 6f9d451..2b8df82 100644 --- a/src/islands/Counter.tsx +++ b/src/islands/Counter.tsx @@ -1,15 +1,14 @@ -import { useSignal } from "@preact/signals"; +import { Signal } from "@preact/signals"; import { ComponentChildren } from "preact"; import { Button } from "../components/Button.tsx"; import { Card } from "../components/Card.tsx"; interface Props { + count: Signal; children: ComponentChildren; } -export default function Counter({ children }: Props) { - const count = useSignal(0); - +export default function Counter({ count, children }: Props) { return (
diff --git a/src/islands/NextContentButton.tsx b/src/islands/NextContentButton.tsx index 156c359..b15c492 100644 --- a/src/islands/NextContentButton.tsx +++ b/src/islands/NextContentButton.tsx @@ -9,7 +9,7 @@ export default function NextContentButton({ name }: Props) { return ( (id.value += 1)} diff --git a/src/routes/_middleware.ts b/src/routes/_middleware.ts index 6c0c4d3..575573d 100644 --- a/src/routes/_middleware.ts +++ b/src/routes/_middleware.ts @@ -35,6 +35,7 @@ export async function handler( } const origin = req.headers.get("Origin") || "*"; + ctx.state.data = "myData"; const resp = await ctx.next(); const headers = resp.headers; @@ -49,7 +50,6 @@ export async function handler( `${HTTP_METHOD.POST}, ${HTTP_METHOD.OPTIONS}, ${HTTP_METHOD.GET}, ${HTTP_METHOD.DELETE}, ${HTTP_METHOD.PUT}`, ); - ctx.state.data = "myData"; resp.headers.set("server", "fresh server"); return resp; } diff --git a/src/routes/index.tsx b/src/routes/index.tsx index d8c8342..cb47e56 100644 --- a/src/routes/index.tsx +++ b/src/routes/index.tsx @@ -1,4 +1,5 @@ import { Handlers, PageProps } from "$fresh/server.ts"; +import { useSignal } from "@preact/signals"; import { Link } from "../components/Link.tsx"; import Counter from "../islands/Counter.tsx"; @@ -12,6 +13,7 @@ export const handler: Handlers = { export default function Home({ data }: PageProps) { const name = nameList[Math.floor(Math.random() * 5)]; + const count = useSignal(0); return (
@@ -30,9 +32,9 @@ export default function Home({ data }: PageProps) {
-

Counter Test

+

Counter

- +

This text is rendered on the server

diff --git a/src/routes/search.tsx b/src/routes/search.tsx index 071c98f..05c35c4 100644 --- a/src/routes/search.tsx +++ b/src/routes/search.tsx @@ -32,7 +32,7 @@ export default function Page({ data }: PageProps) {