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:

  1. 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'    },    {      id: 3,      title: 'Finish homework'    }  ];  router.get('/todo/list', (req, res, next) => {    res.json({      response: todo    });  });  export default router;
File: src/server/controllers/api.js
  1. The second step is to import this API controller into our src/server/index.js file and add it as middleware on the /api route: ...

Get React Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.