Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Learn React with TypeScript

You're reading from   Learn React with TypeScript A beginner's guide to reactive web development with React 18 and TypeScript

Arrow left icon
Product type Paperback
Published in Mar 2023
Publisher Packt
ISBN-13 9781804614204
Length 474 pages
Edition 2nd Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Carl Rippon Carl Rippon
Author Profile Icon Carl Rippon
Carl Rippon
Arrow right icon
View More author details
Toc

Table of Contents (19) Chapters Close

Preface 1. Part 1: Introduction
2. Chapter 1: Introducing React FREE CHAPTER 3. Chapter 2: Introducing TypeScript 4. Chapter 3: Setting Up React and TypeScript 5. Chapter 4: Using React Hooks 6. Part 2: App Fundamentals
7. Chapter 5: Approaches to Styling React Frontends 8. Chapter 6: Routing with React Router 9. Chapter 7: Working with Forms 10. Part 3: Data
11. Chapter 8: State Management 12. Chapter 9: Interacting with RESTful APIs 13. Chapter 10: Interacting with GraphQL APIs 14. Part 4: Advanced React
15. Chapter 11: Reusable Components 16. Chapter 12: Unit Testing with Jest and React Testing Library 17. Index 18. Other Books You May Enjoy

Questions

Answer the following questions to reinforce what you have learned in this chapter:

  1. What is wrong with the following component definition?
    export function important() {
      return <div>This is really important!</div>;
    }
  2. A component with a prop is defined as follows:
    export function Name({ name }) {
      return <div>name</div>;
    }

The value of the prop isn’t output though. What is the problem?

  1. Component props are passed into a component as follows:
    <ContactDetails name="Fred" email="[email protected]" />

The component is then defined as follows:

export function ContactDetails({ firstName, email }) {
  return (
    <div>
      <div>{firstName}</div>
      <div>{email}</div>
    </div>
  );
}

The name Fred isn’t output though. What is the problem?

  1. What is wrong with how the click event is handled in the following JSX:
    <button click={() => console.log("clicked")}>
      Click me
    </button>;
  2. What is the initial value of the loading state defined here?
    const [loading, setLoading] = useState(true);
  3. What is wrong with how the state is set in the following component?
    export function Agree() {
      const [agree, setAgree] = useState();
      return (
        <button onClick={() => agree = true}>
          Click to agree
        </button>
      );
    }
  4. The following component implements an optional Agree event. What is wrong with this implementation?
    export function Agree({ onAgree }) {
      function handleClick() {
        onAgree();
      }
      return (
        <button onClick={handleClick}>
          Click to agree
        </button>
      );
    }
You have been reading a chapter from
Learn React with TypeScript - Second Edition
Published in: Mar 2023
Publisher: Packt
ISBN-13: 9781804614204
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime