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>
);
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" } });
}