Book Image

Redux Quick Start Guide

By : James Lee, Tao Wei, Suresh Kumar Mukhiya
Book Image

Redux Quick Start Guide

By: James Lee, Tao Wei, Suresh Kumar Mukhiya

Overview of this book

Starting with a detailed overview of Redux, we will follow the test-driven development (TDD) approach to develop single-page applications. We will set up JEST for testing and use JEST to test React, Redux, Redux-Sage, Reducers, and other components. We will then add important middleware and set up immutableJS in our application. We will use common data structures such as Map, List, Set, and OrderedList from the immutableJS framework. We will then add user interfaces using ReactJS, Redux-Form, and Ant Design. We will explore the use of react-router-dom and its functions. We will create a list of routes that we will need in order to create our application, and explore routing on the server site and create the required routes for our application. We will then debug our application and integrate Redux Dev tools. We will then set up our API server and create the API required for our application. We will dive into a modern approach to structuring our server site components in terms of Model, Controller, Helper functions, and utilities functions. We will explore the use of NodeJS with Express to build the REST API components. Finally, we will venture into the possibilities of extending the application for further research, including deployment and optimization.
Table of Contents (16 chapters)
Title Page
Copyright and Credits
Dedication
About Packt
Contributors
Preface
Index

Preface

This book explores methodologies for developing a scalable, modern web application using cutting-edge, frontend technologies. It is intended for web developers, frontend developers, and novice programmers who want to use React and Redux to develop a modern web application. In this book, we will show you how you can integrate Redux with React and other frontend JavaScript frameworks efficiently, and manage application states effectively. Finally, we will explore the architecture of Redux Saga and see how Saga can be used in handling side effects. We will follow the TDD (test-driven development) paradigm in this book, where we test each piece of code we develop. We will use the JEST framework for testing. In addition to this, we will learn about advanced debugging techniques using Redux Dev tools. In this book, we will build a simple, multilingual hospital management system to perform CRUD (Create, Read, Update, and Delete) on users. We will use React to build interactive user interfaces, and we will utilize Redux Form and Ant Design to exploit user interfaces to meet our needs. Finally, we will explore using styled-components to include CSS in our application.

To develop a scalable web application, the project architecture, correct tooling, and utilization of the correct stack is very important. With numerous options, developers easily get confused about the choice of database, the choice of frontend technologies, which type of module bundler to use, and so on. In this book, we will guide users through a single application architecture paradigm using cutting edge technology, including ReactJS with Redux for state management, and Redux Saga for handling side effects.

Who this book is for

Any web developer or UI/UX developer will be able to benefit from this book. It will guide you seamlessly from the beginner concepts of setting up tools, to the concepts of advanced debugging. In addition to this, the book will consolidate use of the TDD paradigm, which will help you to understand the logic easily and verify that the code written is valid. In addition to this, the book will help you to create a full production app ready to be hosted on the server of your choice.

What this book covers

Chapter 1, Understanding Redux, provides a detailed overview of Redux, its fundamental principles, and a unified approach to the Redux echo system. In addition to this, we will discuss the Redux life cycle, action creators, Redux, and Redux Store. We will discuss in detail the need for these components in the management of state. Finally, we will initiate our project and set up Node.js, webpack, Babel, Redux, and Yarn.

Chapter 2, Testing, follows the TDD approach to developing single page applications. In this chapter, we will discuss why the TDD approach is efficient in building scalable systems. We will also explore how we can set up JEST for testing and how we can use JEST to test React, Redux, Redux Sage, Reducers, and other components.

Chapter 3, Routing, examines routing and the need for it. We will then explore the use of react-router-dom and its functions. We will create a list of routes that we will need in order to create our application. In addition, we will configure react-router-redux in our application and explore the differences between react-router-dom and react-router-redux. Finally, we will explore routing on the server site and create the routes required for our application.

Chapter 4, Concept of Immutability, deals with immutability and its importance. We will set up Immutable JS in our application and convert our reducers to stores in the Immutable JS architecture. We will be using some of the most common data structures, such as Map, List, Set, and OrderedList from the Immutable JS framework. Finally, we will explore how Immutable JS can be tested.

Chapter 5, React with Redux, deals with building interactive component using ReactJS. Moreover, we will be connecting React with Redux, understanding the component life cycle, and the various states in React, as well as the various performance parameters of React components. Finally, we will continue our application and add user interfaces using ReactJS, Redux Form, and Ant Design.

Chapter 6, Extending Redux byMiddleware, explores middleware and the need for it. In addition, we will continue our application and add three important middlewares to our application, including Redux Store middleware, Redux Saga middleware, and language middleware. We will explore other aspects of Redux Saga and discuss how it can be used in handling side effects.

Chapter 7, Debugging Redux, examines the concept of debugging and the types of tools we can use in order to debug our application. It is highly unlikely that the user will code everything with one hundred percent accuracy. Errors may include logical errors, syntax errors, or semantic errors. Understanding errors from the browser, library, or server is a very important skill. Here, we will explore how we can integrate Redux Dev tools. In addition, we will integrate Hot Module Reloading and explore its benefits. Finally, we will learn about using Redux Dev tools.

Chapter 8, Understanding the REST API, covers the setting up of our API server and creating the API required for our application. We will create GET, POST, PUT, and DELETE routes for our required module. We will explore a modern approach to structuring our server site components in terms of Model, Controller, Helper, and utilities' functions. We will explore the use of Node.js with Express to build the RESTful API components. Finally, we will explore the possibilities of extending the application for the purpose of further research, such as deployment, and optimization.

To get the most out of this book

To get the most out of this book, we assume that readers will have the following prerequisite knowledge: an understanding of JavaScript, object-oriented JavaScript, the concurrency model, and event loop; an understanding of functional programming involving the concepts of pure functions, functional composition, avoiding shared state, avoiding mutation, and avoiding side effects; an understanding of the different approaches to programming, including imperative and declarative approaches; and a basic understanding of database management systems.

We also expect readers to follow the resources that are highlighted as further reading at the end of each chapter. In addition to this, all the code shared in GitHub will not be the only solution. There may be multiple ways to solve the same problem. What we have presented in this book is just one of these ways, involving open source technologies.  

Download the example code files

You can download the example code files for this book from your account at www.packt.com. If you purchased this book elsewhere, you can visit www.packt.com/support and register to have the files emailed directly to you.

You can download the code files by following these steps:

  1. Log in or register at www.packt.com.
  2. Select the SUPPORT tab.
  3. Click on Code Downloads & Errata.
  4. Enter the name of the book in the Search box and follow the onscreen instructions.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

  • WinRAR/7-Zip for Windows
  • Zipeg/iZip/UnRarX for Mac
  • 7-Zip/PeaZip for Linux

The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Redux-Quick-Start-Guide. In case there's an update to the code, it will be updated on the existing GitHub repository.

We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Conventions used

There are a number of text conventions used throughout this book.

CodeInText: Indicates code words in the text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: "According to the BMI scale, someonewith bmi between 30.0 and 54 is said to have obesity"

A block of code is set as follows:

import { BrowserRouter } from 'react-router-dom';
ReactDOM.render(
<BrowserRouter>
<App />
</BrowserRouter>,
document.getElementById('root')
);

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

<Route
path="/about"
render={() => (
<div> This is about us page. </div>
)}
/>

Any command-line input or output is written as follows:

$ yarn add connected-react-router --exact

Bold: Indicates a new term, an important word, or words that you see on screen. For example, words in menus or dialog boxes appear in the text like this. Here is an example: "Select System info from the Administration panel."

Note

Warnings or important notes appear like this.

Note

Tips and tricks appear like this.

Get in touch

Feedback from our readers is always welcome.

General feedback: If you have questions about any aspect of this book, mention the book title in the subject of your message and email us at [email protected].

Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you would report this to us. Please visit www.packt.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details.

Piracy: If you come across any illegal copies of our works in any form on the internet, we would be grateful if you would provide us with the location address or website name. Please contact us at [email protected] with a link to the material.

If you are interested in becoming an author: If there is a topic that you have expertise in, and you are interested in either writing or contributing to a book, please visit authors.packtpub.com.

Reviews

Please leave a review. Once you have read and used this book, why not leave a review on the site that you purchased it from? Potential readers can then see and use your unbiased opinion to make purchase decisions, we at Packt can understand what you think about our products, and our authors can see your feedback on their book. Thank you!

For more information about Packt, please visit packt.com.