Implementing promises with Server-Side Rendering
In the last recipe, we saw how SSR works, but that recipe was limited to displaying the SSR with simple components. In this recipe, we will learn how to implement promises to connect our components to Redux, use an API to get data and render the components using SSR.
Getting ready
We are going to use the same code from the last recipe, but we will make some changes. In this recipe, we need to install these packages:
npm installaxios babel-preset-stage-0 react-router-dom redux-devtools-extension redux-thunk
How to do it...
For this recipe, we are going to implement a basic todo list pulled from an API to show how to connect Redux to our application using SSR:
- The first thing we need to do is to add a simple API to display a to-do list:
import express from 'express'; const router = express.Router(); // Mock data, this should come from a database.... const todo = [ { id: 1, title: 'Go to the Gym' }, { id: 2, title: 'Dentist Appointment...