Skip to content

Instantly share code, notes, and snippets.



Created Aug 6, 2019
What would you like to do?
Serverside rendered react app
import express from "express";
import React from "react";
import { renderToString } from "react-dom/server";
import App from "./client/app";
const app = express();
const port = 3000;
const HTML = (req, context) => {
const body = renderToString(<App />);
return `<html>
<title>React basic SSR </title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<body style="margin:0;">
<div id="app">
<script src="client.js"></script>
const context = {};
app.get("/", (req, res) => {
return res.send(HTML(req, context));
app.listen(port, () => console.log(`Example app listening on port ${port}!`));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment