Public
HTTP (deprecated)
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Readme

SSR Framework for val.town

Usage

The router map url paths to component vals.

Component vals must export a React Component as their default export:

export default function() { <h1>Hello World!</h1> }

Optionally, you can define an handler next to your component, allowing you to handle query params or form inputs.

Use the ctx.render function to pass props to your component.

export const handler: Handler = (ctx) => { const url = new URL(ctx.req.url); const params = new URLSearchParams(url.search); return ctx.render({ name: params.get("name") }); }; export default function(props: {name?: string}) { <h1>Hello { name || "World }!</h1> }
1
2
3
4
5
6
7
8
9
import { hydrate } from "https://esm.town/v/pomdtr/ssr";
import { Hono } from "npm:hono@4.0.7";
const app = new Hono();
app.all("/", hydrate("pomdtr/example_component"));
app.all("/greet/:name", hydrate("pomdtr/example_greet_component"));
export default app.fetch;
pomdtr-ssr_router.web.val.run
February 26, 2024