• Townie
    AI
  • Blog
  • Docs
  • Pricing
  • We’re hiring!
Log inSign up
jxnblk

jxnblk

ReactStatic

Public
Like
ReactStatic
Home
Code
2
README.md
main.tsx
Branches
1
Pull requests
Remixes
History
Environment variables
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
Sign up now
Code
/
Code
/
Search
README.md

React SSR for Val Town

Usage

Create val
/** @jsxImportSource https://esm.sh/react */ import { render, React } from "https://esm.town/v/jxnblk/ReactStatic"; function App() { return ( <html> <body> <h1>ReactStatic</h1> <p>React SSR in Val Town</p> </body> </html> ); } export default render(App, []);

Middleware

Custom middleware can be added in an array as the second argument. Middleware can add data to the req.data object or return a response for things like API endpoints.

Create val
export default render(App, [ analytics, robots("User-agent: *\nAllow: /"), getInitialProps ])

robots.txt

ReactStatic has a built-in middleware to handle request to /robots.txt

Create val
import { render, robots } from "https://esm.town/v/jxnblk/ReactStatic"; // ... export default render(App, [ robots("User-agent: *\nAllow: /"), ])

Add a backend request handler

Create val
// example middleware async function api (req: Request, res: Response, next): Promise<Response> { if (req.pathname !== "/api") return next(); if (req.method === "POST") { return Repsonse.json({ message: "Hello POST request" }); } return Response.json({ ok: true }); } export default render(App, [ api ]);

Fetch data on the server to set initial props

Create val
// example middleware async function getInitialProps (req: Request, res: Response, next) { // fetch data or do async work to pass as props to the component req.data = { hello: "props", }; return next(); } export default render(App, [ getInitialProps ]);

Starter template

Create val
/** @jsxImportSource https://esm.sh/react@18.3.1 */ import { render } from "https://esm.town/v/jxnblk/ReactStatic"; function App () { return ( <html> <head> <title>ReactStatic</title> </head> <body> hello </body> </html> ); } export default render(App, []);

React requires matching versions for SSR and hydration -- ensure you import react@18.3.1 when using this library.

Inspired by https://www.val.town/v/stevekrouse/react_http & https://www.val.town/v/stevekrouse/reactClientDemo

Migrated from folder: _LEAVE_AS_IS/ReactStatic

Code
README.mdmain.tsx
FeaturesVersion controlCode intelligenceCLI
Use cases
TeamsAI agentsSlackGTM
DocsShowcaseTemplatesNewestTrendingAPI examplesNPM packages
PricingNewsletterBlogAboutCareers
We’re hiring!
Brandhi@val.townStatus
X (Twitter)
Discord community
GitHub discussions
YouTube channel
Bluesky
Terms of usePrivacy policyAbuse contact
© 2025 Val Town, Inc.