Book Image

React 16 Essentials - Second Edition

By : Christopher Pitt, Artemij Fedosejev, Adam Boduch
Book Image

React 16 Essentials - Second Edition

By: Christopher Pitt, Artemij Fedosejev, Adam Boduch

Overview of this book

React 16 Essentials, Second Edition, fully updated for React 16, takes you on a fast-paced journey through building your own maintainable React 16 applications. React experts Artemij Fedosejev and Adam Boduch give you all the essentials you need to know and start working with React 16, in this new edition of the best-selling React.js Essentials title. You'll find the latest React 16 code updates, assessment of React Fiber, new coverage of Redux, and how to work as a modern React developer. The authors offer you their current assessment of React Fiber, and you'll soon be exploring React 16 hands on, creating your own single and multiple user interface elements with React 16. You'll then see how to create stateless and stateful components and make them reactive. You'll also learn to interact between your components and lifecycle methods, and gauge how to effectively integrate your user interface components with other JavaScript libraries. Delve deep into the core elements of the Redux architecture and learn how to manage your application and data persistence. Then go the extra mile with the Jest test framework, and run multiple tests on your applications and find solutions to scale without complexity. Today React is used by Facebook, Instagram, Khan Academy, and Imperial College London, to name a few. Many new users recognize the benefits of React and adopt it in their own projects, forming a fast-growing community. The speed at which React has evolved promises a bright future for anyone who invests in learning it today. Let Artemij and Adam bring you a brand new look at React 16 and React Fiber, and move your web development into the future.
Table of Contents (20 chapters)
React 16 Essentials Second Edition
About the Authors
About the Reviewers
Customer Feedback
Free Chapter
What's New in React 16


A lot has changed in the React ecosystem since the first edition of React Essentials. More people are building React applications, there are mature libraries and frameworks that support React applications, and React 16 has been released. The explosive growth of React over such a short period of time can be attributed to a number of factors: the excellent community and related resources, the vastness of the React ecosystem and the maturation of certain staple projects, and of course, the React team and their willingness to make developer feedback a priority item as the project continues to evolve.

I feel privileged to be involved with such an important React title. As the name suggests, this book is aimed at teaching the essentials of React. This latest edition reflects changes in the latest version of React, using Redux for managing state, and the JavaScript language itself.

Join me. Let's become experts as React becomes the standard for building user interfaces.

What this book covers

Chapter 1, What's New in React 16, introduces the major changes in React 16. This includes the fundamental changes to how rendering and reconciliation work under the hood, and other new features that are exposed via the API.

Chapter 2, Installing Powerful Tools for Your Project, outlines the goal of this book and explains what modern tools you need to install in order to build React applications efficiently. It introduces each tool and provides step-by-step instructions on how to install each of them. Then, it creates a structure for the project that we'll be building in this book.

Chapter 3, Creating Your First React Element, explains how to install React and introduces virtual DOM. Then, it explains what React Element is and how to create and render one with native JavaScript syntax. Finally, it introduces the JSX syntax and shows how to create React Elements using JSX.

Chapter 4, Creating Your First React Component, introduces React components. It explains the difference between stateless and stateful React components and how to decide which one to use. Then, it guides you through the process of creating both kinds.

Chapter 5, Making Your React Components Reactive, explains how to solve a problem with React and walks you through the process of planning your React application. It creates a React component that encapsulates the entire React application that we build in this book. It explains the relationship between parent and child React components.

Chapter 6, Using Your React Components with Another Library, explores how to use third-party JavaScript libraries with your React components. It introduces the lifecycle of your React components, demonstrates how to use mounting methods, and shows how to create new React components for our book's project.

Chapter 7, Updating Your React Components, introduces the updating methods for the lifecycles of your React components. This covers how to use CSS styles in JavaScript. It explains how to validate and set the default properties of the components.

Chapter 8, Building Complex React Components, focuses on building more complex React components. It explores the details of how to implement different React components and how to put them together into one coherent and fully functional React application.

Chapter 9, Testing Your React Application with Jest, explains the idea of unit testing and how to write and run your unit tests with Jest. It also demonstrates how to test your React components. It discusses test suites, specs, expectations, and matchers.

Chapter 10, Supercharging Your React Architecture with Flux, discusses how to improve the architecture of our React application. It introduces the Flux architecture and explains the role of dispatchers, stores, and action creators.

Chapter 11, Preparing Your React Application for Painless Maintenance with Flux, explains how to decouple concerns in your React application with Flux. It refactors our React application to allow painless maintainability in the future.

Chapter 12, Refining Your Flux Apps with Redux, walks you through the main features of the Flux library, followed by a complete refactoring of an application to use Redux as the main mechanism to control state.

What you need for this book

First of all, you need the latest version of a modern web browser, such as Google Chrome or Mozilla Firefox:

Second, you will need to install Git, Node.js, and npm. You will find detailed instructions on how to install and use them in Chapter 2, Installing Powerful Tools for Your Project.

Finally, you will need a code editor. I recommend Sublime Text ( Alternatively, you can use Atom (, Brackets (, Visual Studio Code (, or any other editor of your choice.

Who this book is for

This book is intended for frontend developers who want to build scalable and maintainable user interfaces for the web. Some core knowledge of JavaScript, HTML, and CSS is the only thing you need to know to start benefiting from the revolutionary ideas that React.js brings into the web development world. If you have previous experience with jQuery or Angular.js, then you will benefit from understanding how React.js is different and how to take advantage of integrating different libraries with it.


In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: Code words in text are shown as follows: "We can include other contexts through the use of the include directive."

A block of code is set as follows:

import React from 'react';
import { render } from 'react-dom';

const reactElement = React.createElement(
  { className: 'header' }


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

<!doctype html>
  <html lang="en">
      <div id="react-application">
        I am about to learn the essentials of React.js.
      <script src="./snapterest.js"></script>

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

cd ~
git clone

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "clicking on the Next button moves you to the next screen."


Warnings or important notes appear in a box like this.


Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an email to , and mention the book title via the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for all Packt books you have purchased from your account at If you purchased this book elsewhere, you can visit 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 to our website using your email address and password.

  2. Hover the mouse pointer on the SUPPORT tab at the top.

  3. Click on Code Downloads & Errata.

  4. Enter the name of the book in the Search box.

  5. Select the book for which you're looking to download the code files.

  6. Choose from the drop-down menu where you purchased this book from.

  7. Click on Code Download.

You can also download the code files by clicking on the Code Files button on the book's webpage at the Packt Publishing website. This page can be accessed by entering the book's name in the Search box. Please note that you need to be logged in to your Packt account.

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 We also have other code bundles from our rich catalog of books and videos available at Check them out!

Downloading the color images of this book

We also provide you with a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you understand the changes in the output better. You can download this file from


Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from


Piracy of copyright material on the internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors, and our ability to bring you valuable content.


You can contact us at if you are having a problem with any aspect of the book, and we will do our best to address it.