Skip to content

Instantly share code, notes, and snippets.

@omar2205
Last active November 23, 2022 18:37
Show Gist options
  • Save omar2205/131a9e5d0276f26aea36d65c4d89e051 to your computer and use it in GitHub Desktop.
Save omar2205/131a9e5d0276f26aea36d65c4d89e051 to your computer and use it in GitHub Desktop.
Render React with Deno
// 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