Book Image

Getting Started with React

By : Doel Sengupta, Manu Singhal, Danillo Corvalan
Book Image

Getting Started with React

By: Doel Sengupta, Manu Singhal, Danillo Corvalan

Overview of this book

ReactJS, popularly known as the V (view) of the MVC architecture, was developed by the Facebook and Instagram developers. It follows a unidirectional data flow, virtual DOM, and DOM difference that are generously leveraged in order to increase the performance of the UI. Getting Started with React will help you implement the Reactive paradigm to build stateless and asynchronous apps with React. We will begin with an overview of ReactJS and its evolution over the years, followed by building a simple React component. We will then build the same react component with JSX syntax to demystify its usage. You will see how to configure the Facebook Graph API, get your likes list, and render it using React. Following this, we will break the UI into components and you’ll learn how to establish communication between them and respond to users input/events in order to have the UI reflect their state. You’ll also get to grips with the ES6 syntaxes. Moving ahead, we will delve into the FLUX and its architecture, which is used to build client-side web applications and complements React’s composable view components by utilizing a unidirectional data flow. Towards the end, you’ll find out how to make your components reusable, and test and deploy them into a production environment. Finally, we’ll briefly touch on other topics such as React on the server side, Redux and some advanced concepts.
Table of Contents (18 chapters)
Getting Started with React
About the Authors
About the Reviewers

The jestTypical example of a Testsuite with Mocha, expect, ReactTestUtils and Babel

Let's see a typical example of package.json, which is using the following:

  • Mocha as a testing framework

  • Expect as an assertion library

  • ReactTestUtils to test react-based JavaScript components

  • Babel used as a transcompiler, which changes the ES6 codes into currently compatible (ES5) JavaScript code.

The example of package.json file:

"scripts": {
    "test": "mocha './src/**/*.test.js' --compilers js:babel-core/register",
  "devDependencies": {
    "babel-core": "6.1.4",
    "babel-loader": "6.1.0",
    "babel-preset-es2015": "6.1.4",
    "babel-preset-react": "6.1.4",
    "babel-preset-stage-2": "6.1.2",
    "mocha": "2.3.3",
    "react-addons-test-utils": "0.14.3",

As in the previous examples, within the script object, we keep the the test files and all the test files follow the convention of ending with the .test.js extension. Any extension for the test files can be used. For compilation from ES6 code...