SSR with React and Deno

Posted May 10, 2022 by ynwd ‐ 2 min read

This is the Simple Implementation of Server Side Rendering (SSR) with React and Deno. In this guide you will learn how easy and clean to setup SSR in Fastro.


SSR implementation is quite complicated. Fastro simplifies it with a simple API and minimal config.

It does bundling and hydration at application initiation so that the loading process is faster.

App structure

├── components
│   └── app.tsx
├── static
├── server.tsx
└── deno.json


Create deno configuration file: deno.json. This is used to configure TypeScript on Deno.

  "compilerOptions": {
    "strict": true,
    "jsx": "react-jsx",
    "jsxImportSource": ""

Create app and static dirs

mkdir components && mkdir static
  • components folder is place for react components. This is the default name. If you change it, it will throw an error. See the example to see other implementation.

  • static is folder for hydrated and bundled files created during app initiation. This file will be accessed by the default index.html.


Create react component: components/app.tsx. This is very basic react component. I got it from

// @deno-types=""
import React from "";

const App = () => {
  const [count, setCount] = React.useState(0);
  return (
      <h1>Hello Deno Land!</h1>
      <button onClick={() => setCount(count + 1)}>Click the 🦕</button>
      <p>You clicked the 🦕 {count} times</p>

export default App;


Create routing file: server.tsx

import application, { response } from "";
import rendering from "";
import App from "./components/app.tsx";

const component = rendering(<App />);

const app = application(component)
  .get("/", () => {
    return response(component).render({ title: "Hello world" });

console.log("Listening on: http://localhost:8000");

await app.serve();

In this file we create 2 endpoints:

  • / is the root for react app.
  • /static is where bundle.js available. bundle.js is generated automatically when you run the webapp.

How to run locally

deno run -A --unstable server.tsx

Source-code: ssr-example