Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
React Key Concepts
React Key Concepts

React Key Concepts: Consolidate your knowledge of React's core features

Arrow left icon
Profile Icon Maximilian Schwarzmüller
Arrow right icon
€8.99 €26.99
Full star icon Full star icon Full star icon Full star icon Half star icon 4.9 (61 Ratings)
eBook Dec 2022 590 pages 1st Edition
eBook
€8.99 €26.99
Paperback
€33.99
Subscription
Free Trial
Renews at €18.99p/m
Arrow left icon
Profile Icon Maximilian Schwarzmüller
Arrow right icon
€8.99 €26.99
Full star icon Full star icon Full star icon Full star icon Half star icon 4.9 (61 Ratings)
eBook Dec 2022 590 pages 1st Edition
eBook
€8.99 €26.99
Paperback
€33.99
Subscription
Free Trial
Renews at €18.99p/m
eBook
€8.99 €26.99
Paperback
€33.99
Subscription
Free Trial
Renews at €18.99p/m

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 feature icon AI Assistant (beta) to help accelerate your learning
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

React Key Concepts

2. Understanding React Components and JSX

Learning Objectives

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

– Define what exactly components are

– Build and use components effectively

– Utilize common naming conventions and code patterns

– Describe the relation between components and JSX

– Write JSX code and understand why it's used

– Write React components without using JSX code

– Write your first React apps

Introduction

In the previous section, you learned about React in general, what it is and why you could consider using it for building user interfaces. You also learned how to create React projects with the help of npx create-react-app.

In this chapter, you will learn about one of the most important React concepts and building blocks: React as above, components. You will learn that components are reusable building blocks which are used to build user interfaces. In addition, JSX code will be discussed in greater detail so that you will be able to use the concept of components and JSX to build your own, first, basic React apps.

What Are Components?

A key concept of React is the usage of so-called components. Components are reusable building blocks which are combined to compose the final user interface. For example, a basic website could be made up of a header that includes a navigation bar and a main section that includes an authentication form.

Figure 2.1 An example authentication screen with navigation bar.

If you look at this example page, you might be able to identify various building blocks (i.e., components). Some of these components are even reused.

In the header with the navigation bar you will find the following components:

  • The navigation items (Login and Profile)
  • The Logout button

Below this, the main section displays the following:

  • The container that contains the authentication form
  • The input elements
  • The confirmation button
  • A link to switch to the New Account page

Please note that some components are nested inside other...

What Does React Do with All These Components?

If you follow the trail of all components and their import + export statements to the top, you will find a root.render(...) instruction in the main entry script of the React project. Typically, this main entry script can be found in the index.js file, located in the project's src/ folder. This render() method, which is provided by the React library (to be precise, by the react-dom package), takes a snippet of JSX code and interprets and executes it for you. 

The complete snippet you find in the root entry file (index.js) typically looks like this: 

import React from 'react'; 
import ReactDOM from 'react-dom/client'; 
 
import './index.css'; 
import App from './App'; 
 
const root = ReactDOM.createRoot(document.getElementById('root')); 
root.render(<App />); 

The exact code you find in your new React project might...

JSX vs HTML vs Vanilla JavaScript

As mentioned above, React projects typically contain lots of JSX code. Most custom components will return JSX code snippets. You can see this in all the examples shared thus far, and you will see in basically every React project you will explore, no matter whether you are using React for the browser or for other platforms like react-native.

But what exactly is this JSX code? How is it different from HTML? And how is it related to vanilla JavaScript?

JSX is a feature that's not part of vanilla JavaScript. What can be confusing, though, is that it's also not directly part of the React library.

Instead, JSX is syntactical sugar that is provided by the build workflow that's part of the overall React project. When you start the development web server via npm start or build the React app for production (i.e., for deployment) via npm run build, you kick off a process that transforms this JSX code back to regular JavaScript instructions...

Outputting Dynamic Content

Thus far, in all these examples, the content that was returned was static. It was content like <p>Hello World!</p>—which of course is content that never changes. It will always output a paragraph that says, 'Hello World!'.

At this point in the book, you don't yet have any tools to make the content more dynamic. To be precise, React requires that state concept (which will be covered in a later chapter) to change the content that is displayed (e.g. upon user input or some other event).

Nonetheless, since this chapter is about JSX, it is worth diving into the syntax for outputting dynamic content, even though it's not yet dynamic.

function App() {
  const userName = 'Max';
  return <p>Hi, my name is {userName}!</p>;
};

This example technically still produces static output since userName never changes; but you can already see the syntax for outputting dynamic content...

Summary and Key Takeaways

  • React embraces components: reusable building blocks that are combined to define the final user interface
  • Components must return renderable content, typically JSX code which defines the HTML code that should be produced in the end
  • React provides a lot of built-in components: besides special components like <>…</> you get components for all standard HTML elements
  • To allow React to tell custom components apart from built-in components, custom component names have to start with capital characters, when being used inside of JSX code (typically, PascalCase naming is used therefore)
  • JSX is neither HTML nor a standard JavaScript feature, instead it's syntactical sugar provided by build workflows that are part of all React projects
  • You could replace JSX code with React.createElement(…) calls; but since this leads to significantly more unreadable code, it's typically avoided.
  • When using JSX elements, you...

Apply What You Learned

With this and the previous chapter, you have all the knowledge you need to create a React project and populate it with some first, basic components.

Below, you'll find your first two activities for this book:

Activity 2.1: Creating a React App to Present Yourself

Suppose you are creating your personal portfolio page, and as part of that page, you want to output some basic information about yourself (e.g., your name or age). You could use React and build a React component that outputs this kind of information, as outlined in the following activity.

The aim is to create a React app as you learned it in the previous chapter (i.e., create it via npx create-react-app, run npm start to start the development server) and edit the App.js file such that you output some basic information about yourself. You could, for example output your full name, address, job title or other kinds of information. In the end, it is up to you what content you want to output...

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • A clear, concise explanation of core React 18 functionalities to promote quick, easy reference
  • Gain a deep understanding of key React concepts with the help of step-by-step derivations
  • Work with practical exercises that challenge you to apply your new skills and build your own simple apps

Description

As the most popular JavaScript library for building modern, interactive user interfaces, React is an in-demand framework that’ll bring real value to your career or next project. But like any technology, learning React can be tricky, and finding the right teacher can make things a whole lot easier. Maximilian Schwarzmüller is a bestselling instructor who has helped over two million students worldwide learn how to code, and his latest React video course (React — The Complete Guide) has over six hundred thousand students on Udemy. Max has written this quick-start reference to help you get to grips with the world of React programming. Simple explanations, relevant examples, and a clear, concise approach make this fast-paced guide the ideal resource for busy developers. This book distills the core concepts of React and draws together its key features with neat summaries, thus perfectly complementing other in-depth teaching resources. So, whether you've just finished Max’s React video course and are looking for a handy reference tool, or you've been using a variety of other learning materials and now need a single study guide to bring everything together, this is the ideal companion to support you through your next React projects. Plus, it's fully up to date for React 18, so you can be sure you’re ready to go with the latest version.

Who is this book for?

This React book is for developers who have prior experience with, or who are currently learning, the basics of React. You can use this book as a standalone resource to consolidate your understanding or as a companion guide to a more in-depth course. To get the most value from this book, you should have a basic understanding of the fundamentals of JavaScript, HTML, and CSS.

What you will learn

  • Build modern, user-friendly, and reactive web apps
  • Create components and utilize props to pass data between them
  • Handle events, perform state updates, and manage conditional content
  • Apply styles dynamically and conditionally to create a modern UI
  • Use advanced state management techniques such as React's context API
  • Utilize React router to render different pages for different URLs
  • Understand key best practices and optimization opportunities

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Dec 26, 2022
Length: 590 pages
Edition : 1st
Language : English
ISBN-13 : 9781803240480

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 feature icon AI Assistant (beta) to help accelerate your learning
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Dec 26, 2022
Length: 590 pages
Edition : 1st
Language : English
ISBN-13 : 9781803240480

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.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
€189.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 €5 each
Feature tick icon Exclusive print discounts
€264.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 €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 105.97
React Key Concepts
€33.99
React and React Native
€37.99
React Application Architecture for Production
€33.99
Total 105.97 Stars icon
Banner background image

Table of Contents

14 Chapters
1. React – What and Why Chevron down icon Chevron up icon
2. Understanding React Components and JSX Chevron down icon Chevron up icon
3. Components and Props Chevron down icon Chevron up icon
4. Working with Events and State Chevron down icon Chevron up icon
5. Rendering Lists and Conditional Content Chevron down icon Chevron up icon
6. Styling React Apps Chevron down icon Chevron up icon
7. Portals and Refs Chevron down icon Chevron up icon
8. Handling Side Effects Chevron down icon Chevron up icon
9. Behind the Scenes of React and Optimization Opportunities Chevron down icon Chevron up icon
10. Working with Complex State Chevron down icon Chevron up icon
11. Building Custom React Hooks Chevron down icon Chevron up icon
12. Multipage Apps with React Router Chevron down icon Chevron up icon
13. Managing Data with React Router Chevron down icon Chevron up icon
14. Next Steps and Further Resources Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.9
(61 Ratings)
5 star 91.8%
4 star 4.9%
3 star 1.6%
2 star 1.6%
1 star 0%
Filter icon Filter
Top Reviews

Filter reviews by




Vincenzo Jun 22, 2023
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I have worked with React.js for more than 5 years, I decided to buy this book to refresh my knowledge of the latest best practices.And I must say, the book exceeded my expectations. I quickly came up to speed with unfamiliar concepts, and was then able to refactor/improve my own sets of code, all while gaining a better understanding of React.js from the inside out thanks to chapters 9, 10 and 11.I know Maximilian has a deep knowledge of React having followed his online courses and this book just confirmed how great he is as a Teacher.I definitely recommend this book.
Amazon Verified review Amazon
Carl KK L Feb 18, 2023
Full star icon Full star icon Full star icon Full star icon Full star icon 5
In retrospect, I feel immensely thankful to have discovered Maximilian Schwarzmüller, the author of this book, during the early stage when I just embarked on my career as a developer. Specifically, I took his 100 Days of Code - Web Development Bootcamp on Udemy and, upon completing the course, was able to develop a full-stack web application that had all the functions a standard web app should have, complete with satisfying UI/UX created with the CSS, JavaScript, and Bootstrap knowledge he provided. Maximilian also introduced just enough advanced concepts to ensure that learners not only knew the how, but also the what and why behind the scenes, a crucial aspect of becoming a good web developer.Maximilian also has another online course, React: The Complete Guide, which a friend of mine completed last year. With the knowledge gained from that course alone, my friend secured a frontend developer job requiring React skills and has worked in that position for over six months. This is a testament to the quality of the author and his resources.Now, let's discuss the book itself, focusing on both its form and content.Form:You may be wondering why someone would choose a book over an online video course. As it turns out, our brains process abstract and image content in different regions, which makes it challenging for the brain to achieve high concurrency. This task-switching burden reduces learning efficiency and hinders a learner's ability to digest, ponder, and reflect on the knowledge they have gained. While it's possible to pause, slow down, or speed up a video to accommodate one's pace, it can also be a significant distraction when attempting to understand difficult content. In contrast, a book allows you to ruminate and brainstorm as you learn, connecting the new information with your existing knowledge and forming new synapses. Additionally, a book is a useful reference tool, easy to consult when revisiting a concept or checking certain information. This convenience is not possible with a video course unless you create your own notes with good indexing (which I recommend using the Obsidian app for).Content:Maximilian's book is an outstanding resource for anyone interested in learning the basics of React. The content is well-structured and easy to follow, even if you have very little experience with React (although, as the author clearly states, some fundamental knowledge of JavaScript, HTML, and CSS is necessary). For every concept introduced in React, there are code snippet examples that make it feel like someone is holding your hand and guiding you step by step to proficiency. You can experiment and amend the codes the book provides on your own IDE to gain a deeper understanding through hands-on experience. For more advanced learners, there are additional resources available, such as links to other articles for those who want to delve deeper into the topic. Maximilian also provides insight into the mechanisms of React working behind the scenes of the codes, so you can continue to learn even if you already have some experience with React.Overall, I highly recommend this book to anyone looking to learn React. Maximilian has done an excellent job presenting the material in a clear and accessible way, and you can easily apply the knowledge you gain to real-life projects.
Amazon Verified review Amazon
AL Jan 31, 2023
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This react book helped me learn the ins and outs of react that I did not learn from tutorials on the internet. I found chapter 9: Behind the Scenes of React and Optimization Opportunities, to be useful as It filled in the gaps of my react knowledge, especially as a beginner who needs to refresh my knowledge often. I find this book to be helpful to my needs because I am graduating college this year and I think this book will help out in an entry level developer job. The book is well put together and is easy to follow along. I would recommend this book to anyone starting out with react.
Amazon Verified review Amazon
dramiro Jan 31, 2023
Full star icon Full star icon Full star icon Full star icon Full star icon 5
The writer has extensive teaching experience, with extensive course content on platforms such as Udemy.In this book he demonstrates his ability to transmit his knowledge, explaining in detail each topic of React.The book is a book with interesting topics, suitable for someone who is just starting with React, as well as for an experienced developer who needs to reinforce his knowledge. Max explains in detail the concepts and accompanies them with very good code examples where you can better understand the theory.A great book to have at your fingertips and to be able to consult your doubts on a daily basis.
Amazon Verified review Amazon
J.P.G. Apr 11, 2023
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I had the opportunity to dive into React Key Concepts, and I must say, it's a great book whether you're a React beginner, or a seasoned developer! What I really appreciated about this book is its well-structured and concise approach to the fundamentals of React. It starts with a clear introduction to React and JSX, and then it jumps straight into the meat of React with components, props, events, and state. This is followed by more advanced topics such as custom hooks and React Router, which are essential skills for building complex React apps.The practical exercises are where this book really shines! They offer the perfect mix of challenge and guidance, allowing me to apply what I've learned in a hands-on way. The pacing of the book is also commendable, with a quick-paced overview that doesn't drag on too long.One thing to note is that the book leans more towards React-specific concepts rather than JavaScript foundations, but that's not necessarily a bad thing. If you're new to JavaScript, it's best to pair this book with an introductory text on JS, so you're well-versed in the language before diving into React's nitty-gritty.React Key Concepts is an expertly written and comprehensive book, which I highly recommend to anyone interested in learning or improving their knowledge of React or frontend development in general. Overall, a great source of information and a worthwhile investment in your React skills.
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.