ReactStaticREADME.md14 matches
1React SSR for Val Town
23## Usage
45```tsx
6/** @jsxImportSource https://esm.sh/react */
7import { render, React } from "https://esm.town/v/jxnblk/ReactStatic";
89function App() {
11<html>
12<body>
13<h1>ReactStatic</h1>
14<p>React SSR in Val Town</p>
15</body>
16</html>
2223<!--
24[Live example](https://www.val.town/v/jxnblk/ReactStreamDemo)
25-->
2641### robots.txt
4243ReactStatic has a built-in middleware to handle request to `/robots.txt`
4445```tsx
46import { render, robots } from "https://esm.town/v/jxnblk/ReactStatic";
47// ...
48export default render(App, [
8586```tsx
87/** @jsxImportSource https://esm.sh/react@18.3.1 */
88import { render } from "https://esm.town/v/jxnblk/ReactStatic";
8990function App () {
92<html>
93<head>
94<title>ReactStatic</title>
95</head>
96<body>
104```
105106React requires matching versions for SSR and hydration -- ensure you import `react@18.3.1` when using this library.
107108Inspired by https://www.val.town/v/stevekrouse/react_http & https://www.val.town/v/stevekrouse/reactClientDemo
109110111Migrated from folder: _LEAVE_AS_IS/ReactStatic
ReactStream_migratedmain.tsx16 matches
1/** @jsxImportSource https://esm.sh/react@18.3.1 */
2import { hydrateRoot } from "https://esm.sh/react-dom@18.3.1/client";
3import * as React from "https://esm.sh/react@18.3.1";
45export { React };
67export type RequestHandler = (request: Request) => Promise<Response>;
13export type Middleware = (req: DataRequest, res: Response, callback: NextCallback) => Promise<Response>;
1415export interface ReactStreamProps {
16url: URL;
17pathname: string;
2324export function render<T>(
25/** Root-level React component that renders an entire <html> element
26* including the head and body tags.
27*/
28Component: React.ComponentType<ReactStreamProps>,
29/** On Val Town, use `import.meta.url` for client-side hydration */
30module: string | false,
31/** Optional middleware */
32opts: ReactStreamOptions | Middleware[] = [],
33) {
34const useMiddleware = Array.isArray(opts); // for backwards compat
35const options: ReactStreamOptions = !Array.isArray(opts) ? opts : {};
36const { api, getInitialProps } = options;
374243return async function handler(request: Request): Promise<Response> {
44const main = reactStream(Component, module);
45const middleware: Middleware[] = [
46parseURL,
71export default render;
7273// main react response handler
74const reactStream = (
75Component: React.ComponentType<ReactStreamProps>,
76module: string | false,
77): Middleware =>
78async function(req: DataRequest, res: Response): Promise<Response> {
79const { renderToReadableStream } = await import("https://esm.sh/react-dom@18.3.1/server");
8081const stream = await renderToReadableStream(
91headers.set("Content-Type", "text/html");
9293console.log("react", res.status);
94return new Response(stream, {
95headers,
139};
140/** DEPRECATED: Use middleware instead */
141export interface ReactStreamOptions {
142/** DEPRECATED: Optional text response for robots.txt */
143robots?: string;
myBookmarkManagermain.tsx3 matches
1/** @jsxImportSource https://esm.sh/react@18.2.0 */
2import { Hono } from "https://esm.sh/hono@3.3.1";
3import { createRoot } from "https://esm.sh/react-dom@18.2.0/client";
4import React, { useEffect, useRef, useState } from "https://esm.sh/react@18.2.0";
56function MyBookmarkManager() {
ampleCopperMagpiemain.tsx7 matches
1/** @jsxImportSource https://esm.sh/react@18.2.0 */
2import { AnimatePresence, motion } from "https://esm.sh/framer-motion@10.16.4";
3import { createRoot } from "https://esm.sh/react-dom@18.2.0/client";
4import React, { useEffect, useState } from "https://esm.sh/react@18.2.0";
56function CreativeDeveloperPortfolio() {
19title: "AI Chatbot Platform 🤖",
20description: "Intelligent conversational AI with natural language processing",
21tech: ["Python", "TensorFlow", "React"],
22link: "https://ai-chatbot.example.com",
23image: "https://maxm-imggenurl.web.val.run/ai-chatbot-interface",
26title: "Blockchain Explorer 🔗",
27description: "Real-time cryptocurrency transaction tracker",
28tech: ["Solidity", "Web3.js", "React"],
29link: "https://blockchain-explorer.example.com",
30image: "https://maxm-imggenurl.web.val.run/blockchain-dashboard",
33title: "Smart Home Dashboard 🏠",
34description: "IoT device management and monitoring system",
35tech: ["Node.js", "MQTT", "React Native"],
36link: "https://smart-home.example.com",
37image: "https://maxm-imggenurl.web.val.run/smart-home-dashboard",
41const skills = [
42{ name: "Python", level: 90, color: "bg-blue-500" },
43{ name: "React", level: 85, color: "bg-cyan-500" },
44{ name: "Machine Learning", level: 80, color: "bg-green-500" },
45{ name: "Cloud Computing", level: 75, color: "bg-indigo-500" },
falDemoAppmain.tsx4 matches
1/** @jsxImportSource https://esm.sh/react */
2import { createFalClient } from "https://esm.sh/@fal-ai/client";
3import React, { useState } from "https://esm.sh/react";
4import { createRoot } from "https://esm.sh/react-dom/client";
5import { falProxyRequest } from "https://esm.town/v/stevekrouse/falProxyRequest";
610const [loading, setLoading] = useState(false);
1112const generateImage = async (e?: React.FormEvent) => {
13e?.preventDefault();
14setLoading(true);
1/** @jsxImportSource https://esm.sh/react */
2import { sqlite } from "https://esm.town/v/std/sqlite?v=6";
3import { html } from "https://esm.town/v/stevekrouse/html";
4import { SparklineSVG } from "https://esm.town/v/stevekrouse/sparklineSVGReact";
5import { renderToString } from "npm:react-dom/server";
67function StatusRow({ rows }) {
chatApplicationmain.tsx3 matches
1/** @jsxImportSource https://esm.sh/react@18.2.0 */
2import React, { useState, useEffect, useRef } from "https://esm.sh/react@18.2.0";
3import { createRoot } from "https://esm.sh/react-dom@18.2.0/client";
45function App() {
StripeDemomain.tsx3 matches
1/** @jsxImportSource https://esm.sh/react */
2import confetti from "https://esm.sh/canvas-confetti";
3import React, { useEffect, useState } from "https://esm.sh/react";
4import { createRoot } from "https://esm.sh/react-dom/client";
56function App() {
cerebras_codermain.tsx10 matches
1/** @jsxImportSource https://esm.sh/react@18.2.0 */
2import Cerebras from "https://esm.sh/@cerebras/cerebras_cloud_sdk";
3import { createRoot } from "https://esm.sh/react-dom@18.2.0/client";
4import { Prism as SyntaxHighlighter } from "https://esm.sh/react-syntax-highlighter";
5import React, { useEffect, useState } from "https://esm.sh/react@18.2.0";
6import { STARTER_PROMPTS } from "https://esm.town/v/stevekrouse/cerebras_coder_prompts";
731}: {
32prompt: string;
33setPrompt: React.Dispatch<React.SetStateAction<string>>;
34handleSubmit: (e: React.FormEvent) => void;
35handleStarterPromptClick: (promptItem: PromptItem) => void;
36}) {
117118function App() {
119const previewRef = React.useRef<HTMLDivElement>(null);
120const [prompt, setPrompt] = useState("");
121const [projectId, setProjectId] = useState<number | null>(null);
175}
176177async function handleSubmit(e: React.FormEvent | string) {
178if (typeof e !== "string") {
179e.preventDefault();
674</div>
675<div className="bg-white w-full h-full flex flex-col grow rounded-xl border-2 border-white overflow-hidden">
676<React.Fragment key={iframeKey}>
677<iframe
678srcDoc={code}
680className="w-full grow"
681/>
682</React.Fragment>
683</div>
684</div>
scientificCalculatorAppmain.tsx3 matches
1/** @jsxImportSource https://esm.sh/react@18.2.0 */
2import React, { useState } from "https://esm.sh/react@18.2.0";
3import { createRoot } from "https://esm.sh/react-dom@18.2.0/client";
45function ScientificCalculator() {