DEV Community

Discussion on: How to server-side render React, hydrate it on the client and combine client and server routes

Collapse
 
michaelcurrin profile image
Michael Currin • Edited

Thanks, this tutorial and code snippets helped a lot! All the other things I looked at where too complex and had extra code. I just needed to know how to combine string rendering and hydration.

A built an app based around your instructions. I hope it helps others here too.

GitHub logo MichaelCurrin / react-ssr-quickstart

Starter template for server-side and client-side rendering of a React app βš›οΈ πŸ“¦

React SSR Quickstart βš›οΈ πŸ“¦

Starter template for server-side and client-side rendering of a React app

GitHub tag License

Made with Node.js Package - react Package - express

Preview

Sample screenshot

Use this project

Use this template

About

Background

Based on tutorial:

We set up a client-side React app with some components including an incrementing counter.

On initial page load without JS running, a user or a search engine crawler will see an empty page. So we add a server-side Express app that return an HTML page which acts as a fully-rendered starting point that needs no JS to view in the browser.

We do this by calling ReactDOMServer.renderToString, which unfortunately freezes the app so that ignores user interaction. This is solved by calling React.hydrate on the client, so that the browser can make the initial HTML and turn it into a dynamic app in the usual SPA style.

The…

I went with make instead of concurrently, since make supports parallel jobs already.