Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Beginning React
Beginning React

Beginning React: Simplify your frontend development workflow and enhance the user experience of your applications with React

eBook
₱484.99 ₱693.99
Paperback
₱867.99
Subscription
Free Trial

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Table of content icon View table of contents Preview book icon Preview Book

Beginning React

Creating Components

In this chapter, we are going to learn how to implement React components, how to assemble multiple components into one, and how to manage their internal states. We will explore React component implementation by building a simple application. This application will be implemented step-by-step, in order to put the outlined concepts into practice.

By the end of this chapter, you will be able to:

  • Create basic React components
  • Use JSX to define a component's markup
  • Combine multiple React components in order to create complex UI elements
  • Manage the internal state of React components

Definition of a Component

As defined in the previous chapter, components are the fundamental building blocks of React. Virtually any visual item in a user interface can be a component. From a formal point of view, we would say that a React component is a piece of JavaScript code defining a portion of a user interface.

Consider the following code in a file:

import React from 'react';

class Catalog extends React.Component {
render() {
return <div><h2>Catalog</h2></div>;
}
}

export default Catalog;

This is an ECMAScript 2015 module, defining a basic React component.

It imports the React namespace from the react module and defines the Catalog class by extending the React.Component class. The module exports the Catalog class as a default export.

The interesting part of this definition is the implementation of the render(...

Using JSX

In previous examples, we defined the visual output returned by the render() method of a component by using an HTML-like markup expression. Let's see, for example, the definition of the Catalog component:

import React from 'react';
import './Catalog.css';

class Catalog extends React.Component {
render() {
return <div><h2>Catalog</h2></div>;
}
}

export default Catalog;

The markup expression is not using JavaScript syntax, but it is included inside of a JavaScript code snippet. Why do we mix HTML and JavaScript syntaxes? How is that possible?

Let's start by saying that the HTML-like language describing the React component's visual output is called JSX. This language extends JavaScript with XML expressions in order to simplify the creation of HTML elements within JavaScript code. You...

Composing Components

When defining React components, we can use them as the children of another component by using that component as a React element. We already saw this when we included the Catalog component inside of the App component, but let's analyze this composition further.

Combining Components

We will now see how to combine components in order to create new, complex components:

  1. Open the src/ProductList.js file in the my-shop-03 folder
  2. Follow the text until the end of the section

Let's consider the following component:

import React from 'react';
class ProductList extends React.Component {
render() {
return <ul>
<li>
<h3>Traditional Merlot&lt...

Data Propagation

The ProductList component that we defined in the previous section is impractical. Let's take a look at it again:

import React from 'react';
import './ProductList.css';

class ProductList extends React.Component {
render() {
return <ul>
<li>
<h3>Traditional Merlot</h3>
<p>A bottle of middle weight wine, lower in tannins (smoother),
with a more red-fruited flavor profile.</p>
</li>
<li>
<h3>Classic Chianti</h3>
<p>A medium-bodied wine characterized by a marvelous freshness with
a lingering, fruity finish</p>
</li>
<li>
<h3>Chardonnay</h3>
<p>A dry full-bodied white wine with spicy, bourbon-y notes in an
elegant bottle</p>
...

Managing the Internal State

Components have the ability to store data that can change over time.

When a component shows data that can change over time, we want changes to be shown as soon as possible. For example, consider the ProductList component: it shows a list of products contained in the products array. If a new product is added to the array, we want it to be shown immediately. React provides a mechanism to support the automatic rendering of a component when data changes. Such a mechanism is based on the concept of state.

React state is a property that represents data that changes over time. Every component supports the state property, but it should be used carefully.

Again, consider the ProductList component:

import React from 'react';
import Product from './Product';

class ProductList extends React.Component {
render() ...

Summary

In this chapter, we started to create React components and explored their basic features. In particular, we:

  • Learned how to define a component as a class derived from React.Component, and how to import specific CSS styles
  • Explored the syntax of JSX, which allows us to quickly define the graphical aspect of a component and use React components that were defined elsewhere
  • Combined React components in order to build other components
  • Used state management features so that React components automatically update their visual representation when data changes

In the next chapter, we will analyze how to manage user interaction with a React-based application; in other words, how to capture events and make a UI react to those events.

Left arrow icon Right arrow icon

Key benefits

  • Elaborately explains basics before introducing advanced topics
  • Explains creating and managing the state of components across applications
  • Implement over 15 practical activities and exercises across 11 topics to reinforce your learning

Description

Projects like Angular and React are rapidly changing how development teams build and deploy web applications to production. In this book, you’ll learn the basics you need to get up and running with React and tackle real-world projects and challenges. It includes helpful guidance on how to consider key user requirements within the development process, and also shows you how to work with advanced concepts such as state management, data-binding, routing, and the popular component markup that is JSX. As you complete the included examples, you’ll find yourself well-equipped to move onto a real-world personal or professional frontend project.

Who is this book for?

If you are a frontend developer who wants to create truly reactive user interfaces in JavaScript, then this is the book for you. For React, you’ll need a solid foundation in the essentials of the JavaScript language, including new OOP features that were introduced in ES2015. An understanding of HTML and CSS is assumed, and a basic knowledge of Node.js will be useful in the context of managing a development workflow, but is not essential.

What you will learn

  • Understand how React works within a wider application stack
  • Analyze how you can break down a standard interface into specific components
  • Successfully create your own increasingly complex React components with HTML or JSX
  • Correctly handle multiple user events and their impact on overall application state
  • Understand the component lifecycle to optimize the UX of your application
  • Configure routing to allow effortless, intuitive navigation through your components

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Jul 25, 2018
Length: 96 pages
Edition : 1st
Language : English
ISBN-13 : 9781789534924
Vendor :
Facebook
Languages :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want

Product Details

Publication date : Jul 25, 2018
Length: 96 pages
Edition : 1st
Language : English
ISBN-13 : 9781789534924
Vendor :
Facebook
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just ₱260 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just ₱260 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 5,869.97
Beginning React
₱867.99
Hands-On Full Stack Development with Spring Boot 2.0  and React
₱2500.99
Full-Stack React Projects
₱2500.99
Total 5,869.97 Stars icon

Table of Contents

4 Chapters
Introducing React and UI Design Chevron down icon Chevron up icon
Creating Components Chevron down icon Chevron up icon
Managing User Interactivity Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.3
(3 Ratings)
5 star 66.7%
4 star 0%
3 star 33.3%
2 star 0%
1 star 0%
Smith Sep 18, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I really liked how the book covers everything you need to make full fledged react apps; It strikes a good balance between theory and practical examples, unlike other resources that waste entire chapter just talking about webpack config! This book is good for those who are comfortable with intermediate level Javascript and for those who want to become productive with React.js quickly. I think this is a great first resource for students, and also a good guide for managers who want a good resource to augment their training materials for their juniors
Amazon Verified review Amazon
Simone Sanfratello Oct 19, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Really like this book, it's very useful to start with React, understanding the main concept and logic.It's a great guide to introduce React to anybody.I like Andrea style, he can explain in a simple, concise way complex concepts.
Amazon Verified review Amazon
Resident01 Feb 21, 2019
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
I really liked the first half of this book but about half way through it just starts throwing things out without enough of an explanation. I do appreciate that it's a small, quick intro to react however I think they condensed a little too much in the last bit of the book. Still usable but I'd only use it as an intro to a larger book.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.