1/** @jsxImportSource https://esm.sh/react@18.2.0 */
2import { renderToString } from "https://esm.sh/react-dom@18.2.0/server";
3import React, { useState } from "https://esm.sh/react@18.2.0";
4import { email } from "https://esm.town/v/std/email";
5import { OpenAI } from "https://esm.town/v/std/openai";
musicalPeachCatfishmain.tsx3 matches
1/** @jsxImportSource https://esm.sh/react@18.2.0 */
2import React from "https://esm.sh/react@18.2.0";
3import { createRoot } from "https://esm.sh/react-dom@18.2.0/client";
4import { boggleSolver } from "https://esm.town/v/alexwein/boggleSolverTownie";
5import { getRandomWord } from "https://esm.town/v/alexwein/getRandomWord";
zanyOrangeCowmain.tsx2 matches
1/** @jsxImportSource https://esm.sh/react@18.2.0 **/
2import { renderToString } from "https://esm.sh/react-dom@18.2.0/server";
34export default (req: Request) => {
notedCoffeeSpidermain.tsx2 matches
1/** @jsxImportSource https://esm.sh/react@18.2.0 **/
2import { renderToString } from "https://esm.sh/react-dom@18.2.0/server";
34export default (req: Request) => {
instagramAnalyzeUnfollowersmain.tsx3 matches
1/** @jsxImportSource https://esm.sh/react */
2import JSZip from "https://esm.sh/jszip@3.10.1";
3import React, { 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?deps=react@18.2.0";
4import { Prism as SyntaxHighlighter } from "https://esm.sh/react-syntax-highlighter?deps=react@18.2.0,react-dom@18.2.0";
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>
1/** @jsxImportSource https://esm.sh/react@18.2.0 */
2import React from "https://esm.sh/react@18.2.0";
3import { createRoot } from "https://esm.sh/react-dom@18.2.0/client";
45const techOptions = {
6frontend: [
7{ name: "React", icon: "⚛️", explanation: "A popular JavaScript library for building user interfaces", complexity: 3 },
8{ name: "Vue", icon: "🖖", explanation: "A progressive framework for building user interfaces", complexity: 2 },
9{ name: "Angular", icon: "🅰️", explanation: "A platform for building web applications", complexity: 4 },
10{ name: "Svelte", icon: "🔥", explanation: "A radical new approach to building user interfaces", complexity: 2 },
11{ name: "Next.js", icon: "⏭️", explanation: "A React framework with hybrid static & server rendering", complexity: 3 },
12{ name: "Tailwind CSS", icon: "🎨", explanation: "A utility-first CSS framework for rapid UI development", complexity: 2 },
13],
38function client() {
39const root = document.getElementById("root");
40if (root && typeof React !== 'undefined' && React.useState) {
41const { useState, useEffect, useRef } = React;
4243function App() {
252try {
253createRoot(root).render(
254<React.StrictMode>
255<App />
256</React.StrictMode>
257);
258} catch (error) {
259console.error("Error rendering React app:", error);
260root.innerHTML = `<div style="color: red; padding: 20px;">
261<h2>Error Rendering App</h2>
265}
266} else {
267console.error("Root element not found or React is not properly loaded");
268}
269}
ReactStaticmain.tsx13 matches
1/** @jsxImportSource https://esm.sh/react@18.3.1 */
2// import { 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 */
30// module: string | false,
3839return async function handler(request: Request): Promise<Response> {
40const main = reactRender(Component);
41const middleware: Middleware[] = [
42parseURL,
62export default render;
6364// main react response handler
65const reactRender = (
66Component: React.ComponentType<ReactStreamProps>,
67): Middleware =>
68async function(req: DataRequest, res: Response): Promise<Response> {
69const { renderToStaticMarkup } = await import("https://esm.sh/react-dom@18.3.1/server");
7071const html = await renderToStaticMarkup(<Component {...req.data} />);
84headers.set("Content-Type", "text/html");
8586console.log("react", res.status);
87return new Response(html, {
88headers,
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;