Public
HTTP
Forked from stevekrouse/reactClientDemo
wilhelm-reactclientdemo.web.val.run
July 8, 2024
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/** @jsxImportSource https://esm.sh/react */
import React from "https://esm.sh/react";
const Counter = () => {
const [count, setCount] = React.useState(0);
return (
<button onClick={() => setCount(count + 1)}>
I've been clicked {count} times
</button>
);
};
const App = () => (
<html>
<head />
<body>
<h1>Val Town React Client Demo</h1>
<Counter />
</body>
</html>
);
if (typeof document !== "undefined") {
const { hydrateRoot } = await import("https://esm.sh/react-dom/client");
hydrateRoot(document, <App />);
}
export default async function(req: Request): Promise<Response> {
const { renderToReadableStream } = await import("https://esm.sh/react-dom/server");
const stream = await renderToReadableStream(<App />, { bootstrapModules: [import.meta.url] });
return new Response(stream, { headers: { "content-type": "text/html" } });
}
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
July 8, 2024