ReactStreammain.tsx16 matches
1/** @jsxImportSource https://esm.sh/react */
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;
hungryWhiteLeoponmain.tsx4 matches
4* information in a SQLite database. The app provides a user interface to view, add, and edit coffee shop reviews.
5*
6* It uses React for the frontend, the Nominatim API for initial coffee shop data,
7* and Val Town's SQLite for data persistence.
8*/
910/** @jsxImportSource https://esm.sh/react */
11import React, { useEffect, useState } from "https://esm.sh/react";
12import { createRoot } from "https://esm.sh/react-dom/client";
1314function App() {
1/**
2* This chat application allows users to post messages and view a log of all messages.
3* It uses SQLite for persistence and React for the frontend.
4* The server handles message posting and retrieval, while the client renders the UI.
5*/
6/** @jsxImportSource https://esm.sh/react */
7import React, { useState, useEffect } from "https://esm.sh/react";
8import { createRoot } from "https://esm.sh/react-dom/client";
910interface Message {
28};
2930const handleSubmit = async (e: React.FormEvent) => {
31e.preventDefault();
32if (!newMessage.trim()) return;
1/**
2* This val creates an interactive tech stack wizard that generates a video game-style inventory screen.
3* It uses React for the UI, leverages emoji and Unicode symbols for a visually rich experience, and
4* incorporates Tailwind CSS for elegant, grayscale styling.
5* The wizard allows users to select tools, libraries, and APIs, then displays them in a shareable format.
6*/
78/** @jsxImportSource https://esm.sh/react */
9import React, { useState } from "https://esm.sh/react";
10import { createRoot } from "https://esm.sh/react-dom/client";
1112// Define tech options with emojis or Unicode symbols as icons
13const techOptions = [
14{ name: "React", icon: "⚛️" },
15{ name: "Vue", icon: "🖖" },
16{ name: "Angular", icon: "🅰️" },
47{ name: "Swift", icon: "🕊️" },
48{ name: "Flutter", icon: "🦋" },
49{ name: "React Native", icon: "📱" },
50{ name: "Electron", icon: "🔬" },
51{ name: "Webpack", icon: "📦" },
techstackinventorymain.tsx5 matches
1/**
2* This val creates a tech stack inventory chooser using React and Tailwind CSS for styling.
3* It allows users to select technologies for different categories and displays the chosen stack.
4*/
5/** @jsxImportSource https://esm.sh/react */
6import React, { useState } from "https://esm.sh/react";
7import { createRoot } from "https://esm.sh/react-dom/client";
89const techCategories = {
10frontend: ["React", "Vue", "Angular", "Svelte"],
11backend: ["Node.js", "Python", "Ruby", "Java"],
12database: ["PostgreSQL", "MongoDB", "MySQL", "SQLite"],
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 }) {
shySapphireLeopardmain.tsx4 matches
1/** @jsxImportSource https://esm.sh/react */
2import { renderToString } from "npm:react-dom/server";
34import React from "https://esm.sh/react";
5import { createRoot } from "https://esm.sh/react-dom/client";
67function App() {
valleGetValsContextWindowmain.tsx9 matches
41{
42type: "http",
43prompt: "Generate a val that uses React to render HTML",
44code: `/** @jsxImportSource https://esm.sh/react */
45import { renderToString } from "npm:react-dom/server";
46
47export const reactExample = (request: Request) =>
48new Response(renderToString(<div>Test {1 + 1}</div>), {
49headers: {
74type: "http",
75prompt: null,
76code: `/** @jsxImportSource https://esm.sh/preact */
77import { render } from "npm:preact-render-to-string";
78
79export const preactExample = (request: Request) =>
80new Response(render(<div>Test {1 + 1}</div>), {
81headers: {
191prompt: "Write a val that renders a website and uses tailwind css",
192type: "http",
193code: `/** @jsxImportSource https://esm.sh/preact */
194import { render } from "npm:preact-render-to-string";
195
196export default async function(req: Request) {
requestCollectormain.tsx4 matches
2* This request collector val saves information about incoming requests
3* and displays summary statistics on the home page. It uses SQLite for
4* persistence and server-side React for rendering the UI. Users can click
5* on a request ID to view full details of that request.
6*/
78/** @jsxImportSource https://esm.sh/react */
9import React from "https://esm.sh/react";
10import { renderToString } from "https://esm.sh/react-dom/server";
1112interface RequestData {
linkInBioTemplatemain.tsx4 matches
2* This web app creates a Side School Seminar location voting system.
3* Users can vote for their preferred seminar location from four options.
4* The app uses React for the frontend and SQLite for storing votes on the backend.
5* The design is inspired by Side.school and includes an image in the first frame.
6* It features a celebration animation when voting, a distinct style for the selected option,
7* and allows users to cancel their vote by clicking on the selected option again.
8*/
9/** @jsxImportSource https://esm.sh/react */
10import React, { useState, useEffect } from "https://esm.sh/react";
11import { createRoot } from "https://esm.sh/react-dom/client";
1213const locations = [