Book Image

Learn React with TypeScript 3

By : Carl Rippon
Book Image

Learn React with TypeScript 3

By: Carl Rippon

Overview of this book

React today is one of the most preferred choices for frontend development. Using React with TypeScript enhances development experience and offers a powerful combination to develop high performing web apps. In this book, you’ll learn how to create well structured and reusable react components that are easy to read and maintain by leveraging modern web development techniques. We will start with learning core TypeScript programming concepts before moving on to building reusable React components. You'll learn how to ensure all your components are type-safe by leveraging TypeScript's capabilities, including the latest on Project references, Tuples in rest parameters, and much more. You'll then be introduced to core features of React such as React Router, managing state with Redux and applying logic in lifecycle methods. Further on, you'll discover the latest features of React such as hooks and suspense which will enable you to create powerful function-based components. You'll get to grips with GraphQL web API using Apollo client to make your app more interactive. Finally, you'll learn how to write robust unit tests for React components using Jest. By the end of the book, you'll be well versed with all you need to develop fully featured web apps with React and TypeScript.
Table of Contents (14 chapters)

To get the most out of this book

You need to know the basics of JavaScript, including the following:

  • An understanding of some of the primitive JavaScript types, such as string, number, Boolean, null, and undefined
  • An understanding of how to create variables and reference them, including arrays and objects
  • An understanding of how to create functions and call them
  • An understanding of how to create conditional statements with the if and else keywords

You need to know the basics of HTML, including the following:

  • An understanding of basic HTML tags, such as div, ul, p, a, h1, and h2, and how to compose them together to create a web page
  • An understanding of how to reference a CSS class to style an HTML element

An understanding of basic CSS is also helpful, but not essential:

  • How to size elements and include margins and padding
  • How to position elements
  • How to color elements

You will need the following technologies installed on your computer:

  • Google Chrome: This can be installed at https://www.google.com/chrome/.
  • Node.js and npm: These are used throughout this book. You can install them at https://nodejs.org/en/download/. If you already have these installed, make sure that Node.js is at least version 8.2 and that npm is at least version 5.2.
  • TypeScript: This can be installed via npm by entering the following command in a terminal:
npm install -g typescript

Download the example code files

You can download the example code files for this book from your account at www.packt.com. If you purchased this book elsewhere, you can visit www.packt.com/support and register to have the files emailed directly to you.

You can download the code files by following these steps:

  1. Log in or register at www.packt.com.
  2. Select the SUPPORT tab.
  3. Click on Code Downloads & Errata.
  4. Enter the name of the book in the Search box and follow the onscreen instructions.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

  • WinRAR/7-Zip for Windows
  • Zipeg/iZip/UnRarX for Mac
  • 7-Zip/PeaZip for Linux

The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Learn-React-with-TypeScript-3. In case there's an update to the code, it will be updated on the existing GitHub repository.

We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Download the color images

Conventions used

There are a number of text conventions used throughout this book.

CodeInText: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: "Let's create a new file called tsconfig.json in the root of our project."

A block of code is set as follows:

import * as React from "react";

const App: React.SFC = () => {
return <h1>My React App!</h1>;
};

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

interface IProps {
title: string;
content: string;
cancelCaption?: string;
okCaption?: string;
}

Any command-line input or output is written as follows:

cd my-components
npm install tslint tslint-react tslint-config-prettier --save-dev

Bold: Indicates a new term, an important word, or words that you see on screen. For example, words in menus or dialog boxes appear in the text like this. Here is an example: "We need to click the Install option to install the extension."

Warnings or important notes appear like this.
Tips and tricks appear like this.