React 16 Tooling
eBook - ePub
No longer available

React 16 Tooling

  1. 298 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub
No longer available

React 16 Tooling

About this book

React 16 Tooling covers the most important tools, utilities, and libraries that every React developer needs to know — in detail.

Key Features

  • Each chapter presents meta-development solutions to help React developers
  • The tools used are presented in a practical, solution-oriented approach with no fluff
  • The chapters are arranged in a logical order that mirrors a typical React development workflow, but you are free to tweak the approaches discussed to fit your own unique style

Book Description

React 16 Tooling covers the most important tools, utilities, and libraries that every React developer needs to know — in detail. As React has grown, the amazing toolset around it has also grown, adding features and enhancing the development workflow. Each of these essential tools is presented in a practical manner and in a logical order mirroring the development workflow. These tools will make your development life simpler and happier, enabling you to create better and more performant apps.

Adam starts with a hand-picked selection of the best tools for the React 16 ecosystem. For starters, there's the create-react-app utility that's officially supported by the React team. Not only does this tool bootstrap your React project for you, it also provides a consistent and stable framework to build upon. The premise is that when you don't have to think about meta development work, more focus goes into the product itself.

Other React tools follow this same approach to automating and improving your development life. Jest makes unit testing quicker. Flow makes catching errors easier. Docker containers make deployment in a stack simpler. Storybook makes developing components straightforward. ESLint makes writing standardized code faster. The React DevTools plugin makes debugging a cinch. React 16 Tooling clears away the barriers so you can focus on developing the good parts. In this book, we'll look at each of these powerful tools in detail, showing you how to build the perfect React ecosystem to develop your apps within.

What you will learn

  • Bootstrap a React application using create-react-app
  • Isolate React component development using Storybook
  • Write effective unit tests for your React components using Jest
  • Ensure that your component code is to standard using ESLint
  • Use browser extensions and built-in component instrumentation to debug React applications
  • Enable type safety in React components with Flowtype
  • Deploy React applications inside a Docker container as part of a larger application stack

Who this book is for

This book is for React developers of any skill level who want to make their lives easier. It helps to have some familiarity with React, but if you are an experienced web developer looking at React, then this book will show you how to build a resilient toolset around you before you begin.

Trusted by 375,005 students

Access to over 1 million titles for a fair monthly price.

Study more efficiently using our study tools.

Information

Year
2018
Print ISBN
9781788835015
Edition
1
eBook ISBN
9781788832083

Debugging Components in the Browser

If you're developing a React web application, you need browser-based tooling to help you see what's happening on the page from the perspective of a React developer. Web browsers today have amazing developer tools installed by default. These are essential if you're doing any kind of web development because they expose what's really going on in terms of DOM, styles, performance, network requests, you name it.
With React, you still need all of this tooling, but you need more than that. The core tenet of React is declarative markup within JavaScript components. If this abstraction isn't present in the web browser tooling that developers rely on for everything else, life is more difficult than it needs to be.
In this chapter, you'll learn:
  • Installing the React Developer Tools browser add-on
  • Locating and selecting React components
  • Manipulating component props and state
  • Profiling component performance

Installing the React Developer Tools add-on

The first step to getting started with React tooling is to install the React Developer Tools browser extension. I'll be using Chrome in the examples throughout this chapter as this is a popular choice. React Developer Tools is also available as an extension for Firefox (https://addons.mozilla.org/en-US/firefox/addon/react-devtools/).
To get the extension installed in Chrome, visit https://chrome.google.com/webstore/category/extensions and search for react developer tools:
The first result should be the extension that you want. Click on the ADD TO CHROME button to install it:
Chrome might warn you that it can change data on websites that you visit. Don't worry, the extension is only activated when you visit React apps:
Once you click on the Add extension button, the extension is marked as installed:
You're all set! With the React Developer Tools Chrome extension installed and enabled, you're ready to start inspecting React components on the page, just like you would with regular DOM elements.

Working with React elements in React Developer Tools

Once you've installed React Developer Tools in Chrome, you'll see a button in the toolbar located to the right of the browser address bar. Here's what mine looks like:
I have several buttons for browser extensions here. You can see the React Developer Tools button at the far right—the one with the React logo. When the button is greyed-out like this, it means that you're not currently on a page running a React application. Go ahead and try clicking on it while you're on some random page:
Now let's use create-react-app to create a new application, the same process you've been following throughout this book:
create-react-app finding-and-selecting-components
Now fire up the development server:
npm start
This should take you directly to the browser page with your React application loaded up in a new tab. Now the React Developer Tools button should look different:
There you go. Since you're on a page that's running a React application, the React Developer Tools button comes alive to let you know that it's available. Try clicking on it now:
Awesome! The React Developer Tools can detect that this is a development build of the React library. This could come in handy in case you ever find yourself in a situation where you accidentally deploy the development build of React to a production environment. Admittedly, this is more difficult to do today with tools like create-react-app where you have the tooling in place to build production versions for free.
Okay, so now that you have your React browser tooling in place, what else can it do for you other than detect the type of React build that's being used by a given app? Let's open up the developer tools pane within Chrome and find out:
You can see all of the regular sections that you normally see in the developer tools pane: Elements, Console, and so on. But there's nothing about React? I happen to have my developer tools pane docked to the right-hand side of my browser window, so you can't see every section. If you're seeing the same thing, you just have to click on the arrow button next to Performance:
Select React from the menu and you'll be taken to the React section of the developer tools panel. Once it loads, you should see the root React component displayed:
If you've used the DOM inspector tool in any browser, this interface should feel familiar. In the main section to the left, you have your React element tree. This should closely resemble your JSX source. To the right of this tree, you have details of the currently-selected element, in this case it's App, and it doesn't define any properties.
If you expand App, you'll see its child HTML markup and other React elements:
This is the default source code after running create-react-app, so there isn't very much of interest under the App element. To further explore React Developer Tools, you'll have to introduce some more components and render more React elements on the page.

Selecting React elements

There are actually two ways to select a React element using React Developer tools. When you open the React section of the developer tools pane, the root element of the React app is automatically selected in the element tree. However, you can expand this element to reveal child elements and select them.
Let's put together a simple app that will help you explore the rendered React elements on the page using React Developer Tools. Starting from the top level, here's the App component:
import React from 'react'; import MyContainer from './MyContainer'; import MyChild from './MyChild'; const App = () => ( <MyContainer>
 <MyChild>child text</MyChild> </MyContainer> ); export default App; 
By looking at this source, you can take a glimpse at the overall structure of the React elements when they're rendered on the page. Next, let's look at the MyContainer component:
import React from 'react'; import './MyContainer.css'; const MyContainer = ({ children }) => ( <section className="MyContainer"> <header> <h1>Container</h1> </header> <article>{children}</article> </section> ); export default MyContainer; 
This component renders some header text and whatever children are passed to it. In this application, you're passing it a MyChild element, so let's look at this component next:
import React from 'react'; const MyChild = ({ children }) => <p>{children}</p>; export default MyChild; 
Now when you run npm start, you should see the following content rendered:
Not much to look at, but you know that everything is working as expected. The app is small enough that you can see every JSX element within the tree view of the React Developer Tools pane:
There is a visual distinction between React elements and other element types, so that they're easier to spot in this tree view. For example, the <MyContainer> element is in one color while the <s...

Table of contents

  1. Title Page
  2. Copyright and Credits
  3. Packt Upsell
  4. Contributors
  5. Preface
  6. Creating a Personalized React Development Ecosystem
  7. Efficiently Bootstrapping React Applications with Create React App
  8. Development Mode and Mastering Hot Reloading
  9. Optimizing Test-Driven React Development
  10. Streamlining Development and Refactoring with Type-Safe React Components
  11. Enforcing Code Quality to Improve Maintainability
  12. Isolating Components with Storybook
  13. Debugging Components in the Browser
  14. Instrumenting Application State with Redux
  15. Building and Deploying Static React Sites with Gatsby
  16. Building and Deploying React Applications with Docker Containers
  17. Another Book You May Enjoy

Frequently asked questions

Yes, you can cancel anytime from the Subscription tab in your account settings on the Perlego website. Your subscription will stay active until the end of your current billing period. Learn how to cancel your subscription
No, books cannot be downloaded as external files, such as PDFs, for use outside of Perlego. However, you can download books within the Perlego app for offline reading on mobile or tablet. Learn how to download books offline
Perlego offers two plans: Essential and Complete
  • Essential is ideal for learners and professionals who enjoy exploring a wide range of subjects. Access the Essential Library with 800,000+ trusted titles and best-sellers across business, personal growth, and the humanities. Includes unlimited reading time and Standard Read Aloud voice.
  • Complete: Perfect for advanced learners and researchers needing full, unrestricted access. Unlock 1.4M+ books across hundreds of subjects, including academic and specialized titles. The Complete Plan also includes advanced features like Premium Read Aloud and Research Assistant.
Both plans are available with monthly, semester, or annual billing cycles.
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 990+ topics, we’ve got you covered! Learn about our mission
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more about Read Aloud
Yes! You can use the Perlego app on both iOS and Android devices to read anytime, anywhere — even offline. Perfect for commutes or when you’re on the go.
Please note we cannot support devices running on iOS 13 and Android 7 or earlier. Learn more about using the app
Yes, you can access React 16 Tooling by Adam Boduch in PDF and/or ePUB format, as well as other popular books in Computer Science & Application Development. We have over one million books available in our catalogue for you to explore.