Public
HTTP (deprecated)
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
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
33
34
35
36
37
38
39
40
/** @jsxImportSource https://esm.sh/react */
import { renderToString } from "npm:react-dom/server";
function HelloWorld() {
return (
<h1 className="text-3xl font-bold underline">
Hello world! Cleaned up, w/ props
</h1>
);
}
function Html({ content }) {
return (
<>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body>
<main>
{content}
</main>
</body>
</>
);
}
function reactExample(request: Request) {
const renderedString = renderToString(<Html content={<HelloWorld />} />);
const response = new Response(renderedString, {
headers: {
"Content-Type": "text/html",
},
});
return response;
}
export default reactExample;
dm-reactexample.web.val.run
March 19, 2024