From fbfdcd719d570410bdf1274c526ae8ea8b79f7bc Mon Sep 17 00:00:00 2001 From: Marvin Hagemeister Date: Tue, 2 Sep 2025 16:04:30 +0200 Subject: [PATCH] docs: migration guide `ctx.render()` (#3314) Fixes https://github.com/denoland/fresh/issues/2969 --- docs/canary/examples/migration-guide.md | 43 +++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/docs/canary/examples/migration-guide.md b/docs/canary/examples/migration-guide.md index d3ac737e..4c008b97 100644 --- a/docs/canary/examples/migration-guide.md +++ b/docs/canary/examples/migration-guide.md @@ -234,6 +234,49 @@ re-use existing objects internally as a minor performance optimization. | `ctx.basePath` | `ctx.config.basePath` | | `ctx.remoteAddr` | `ctx.info.remoteAddr` | +### `ctx.render()` + +The meaning of `ctx.render()` has changed. In Fresh 1.x this was used to pass +data from a handler to a component. In Fresh 2.x this function has been +generalized to render JSX. + +Fresh 1.x: + +```ts +export const handlers = { + async GET(req, ctx) { + const data = await Query(); + await ctx.render({ value: data }); + }, +}; + +export default function Page({ data }) { + // ... +} +``` + +Fresh 2: + +```ts +export const handlers = { + async GET(ctx) { + const data = await Query(); + return { data: { value: data } }; + }, +}; + +export default function Page({ data }) { + // ... +} +``` + +To render JSX in general, use the `ctx.render()` function: + +```tsx +const app = new App() + .get("/", () => ctx.render(

hello

)); +``` + ## `createHandler` The `createHandler` function was often used to launch Fresh for tests. This can