Last active
November 23, 2022 18:37
-
-
Save omar2205/131a9e5d0276f26aea36d65c4d89e051 to your computer and use it in GitHub Desktop.
Render React with Deno
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Run: deno run -A app.ts | |
import fast from 'https://deno.land/x/fast/mod.ts' | |
import * as React from 'https://esm.sh/[email protected]' | |
import * as ReactDOMServer from 'https://esm.sh/[email protected]/server' | |
const Home = () => <h1>Hello from React and Deno</h1> | |
const app = fast() | |
app.get('/', () => { | |
const h = ReactDOMServer.renderToString(<Home />) | |
const body = `<!DOCTYPE html>${str}` | |
const res = new Response(body, { | |
headers: { "content-type": "text/html; charset=utf-8" }, | |
}) | |
return res | |
}) | |
await app.serve() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment