Book Image

React.js Essentials

By : Artemij Fedosejev
Book Image

React.js Essentials

By: Artemij Fedosejev

Overview of this book

Table of Contents (18 chapters)
React.js Essentials
Credits
Foreword
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Preface

Today, the Web is different. The way we build for the Web is different. Faced by the challenges of dealing with unmaintainable imperative code produced by jQuery we had to look for new ways of managing the complexity of modern user interfaces. We needed a new user interface library that would help us build declarative, modular, fast, and scalable frontend applications using JavaScript.

Meet React.js—a JavaScript user interface library developed by Facebook. It brings profound ideas on how to work with the DOM, organize your application's data flow, and think about user interface elements as individual components. And yet, it's only a user interface library that makes no assumptions about the rest of your technology stack.

Combined with Flux, we get a powerful frontend architecture that makes sense not only to experienced developers, but also to those who're just starting their frontend journey.

Dear frontend developers of all experience levels, solving all kind of business challenges, in teams of all sizes with deadlines of all urgency levels... welcome to a better future!

Get ready to be surprised by the simplicity, predictability, and thoughtfulness of React.js.

What this book covers

Chapter 1, 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 2, Create 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 3, Create 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 4, Make 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 5, Use Your React Components with Another Library, explores how to use third-party JavaScript libraries with your React components. It introduces React component's lifecycle, demonstrates how to use mounting methods, and creates new React components for our book's project.

Chapter 6, Update Your React Components, introduces React component lifecycle's updating methods. This covers how to use CSS styles in JavaScript. It explains how to validate and set the default component's properties.

Chapter 7, Build 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 8, Test 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 9, Supercharge 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 dispatcher, stores, and action creators.

Chapter 10, Prepare 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.

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 1, Installing Powerful Tools for Your Project.

Finally, you will need a code editor. I recommend Sublime Text (http://www.sublimetext.com). Alternatively, you can use Atom (https://atom.io), Brackets (http://brackets.io), Visual Studio Code (https://code.visualstudio.com), or any other editor of your preference.

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.

Conventions

In this book, you will find a number of text styles 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: "The entry point to the React library is the React object."

A block of code is set as follows:

var React = require('react');
var ReactDOM = require('react-dom');
var reactElement = React.createElement(
  'h1',
  { className: 'header' }
);
ReactDOM.render(
  reactElement,
  document.getElementById('react-application')
);

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">
  <head>
    <title>Snapterest</title>
  </head>
  <body>
    <div id="react-application">
      I am about to learn the essentials of React.js.
    </div>
    <script src="./snapterest.js"></script>
  </body>
</html>

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

cd ~
git clone https://github.com/snapkite/snapkite-engine.git

New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "You should see the following text: I am about to learn the essentials of React.js."

Note

Warnings or important notes appear in a box like this.

Tip

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 disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.

To send us general feedback, simply e-mail , and mention the book's title in 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 at www.packtpub.com/authors.

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 from your account at http://www.packtpub.com for all the Packt Publishing books you have purchased. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

For this book, the source code files can be downloaded or forked from the following GitHub repository as well: https://github.com/fedosejev/react-essentials

Errata

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 could 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 http://www.packtpub.com/submit-errata, 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 to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted 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.

Questions

If you have a problem with any aspect of this book, you can contact us at , and we will do our best to address the problem. You can also create a new issue on GitHub repository for this book at https://github.com/fedosejev/react-essentials/issues.