Pure React
Introduction
What We’ll Cover
Why Just React?
How This Book Works
How Much Time Will This Take?
Build Small Things and Throw Them Away
Don’t Build a Prototype
So What Should You Build?
Learning With Small Projects
Environment Setup
Prerequisites
Project Directory
Debugging Crash Course
Keep the Console Open!
React Dev Tools
Hello World
How the Code Works
JSX: What and Why
What Is JSX?
JSX Is Compiled to JavaScript
But… Separation of Concerns!
Unseparated Concerns
Working With JSX
Composing Components
Wrap JSX with Parentheses
Return a Single Element
Wrap With a Tag
Fragments
Fragment Syntax
JavaScript in JSX
“If” in JSX
Comments in JSX
Capitalize Component Names
Close Every Element
Exercises
Example: Tweet Component
Rewriting an Existing App
Build the Tweet Component
The let and const Keywords
Add the Buttons and the Time
Props
Passing Props
Receiving Props
Modifying Props
Communicating With Parent Components
Example: Tweet With Props
ES6: Template Strings
What Exactly Should Be Passed as a Prop?
Guidelines for Naming Props
PropTypes
Documentation and Debugging In One
How to Write PropTypes
The Catch
How Do I Validate Thee, Let Me Count the Ways
Example: Tweet with PropTypes
How Explicit Should You Be?
PropTypes as Documentation
Exercises
Children
Different Types of Children
Dealing with the Children
PropTypes for Children
Versus Transclusion in AngularJS
Customizing Children Before Rendering
Exercises
Example: GitHub File List
Break It Into Components
Name the Components
Can You Reuse Anything?
What Data Does Each Component Need?
Top-Down or Bottom-Up?
Keep it Working
FileList
The “key” Prop
FileListItem
Exercises
State in Classes
Example: A Counter
Exercise: Reset Button
setState Is Asynchronous
Functional setState
Shallow vs Deep Merge
Cleaner Syntax for Class Components
Handling Events
Exercises
The Component Lifecycle
Phases
Mounting
Rendering
Unmounting
Error Handling
API Requests in React
Choose an HTTP Library
Axios
Fetch
Fetch Data and Display It
Reddit Trivia
Exercises
State in Functions
Introducing Hooks
But I just learned classes!
The useState Hook
The “Magic” of Hooks
The Call Order Matters
Step-by-step Example of Multiple useState Calls
Rules of Hooks
Update State Based on Previous State
State as an Array
State as an Object
Exercises
Thinking About State
What to Put in State
Thinking Declaratively
How to Develop “Declarative” Thinking
Where to Keep State
“Kinds” of Components
Input Controls
Controlled Inputs
Uncontrolled Inputs
Refs
Exercises
The useReducer Hook
What’s a Reducer?
Ok, but, what about useReducer?
A More Complex Example
Remove an Item
So… is Redux Dead?
Exercises
The useEffect Hook
Limit When an Effect Runs
Focusing an Input Automatically
Only Run on Mount and Unmount
Unmount and Cleanup
Fetch Data With useEffect
Re-fetch When Data Changes
Making Visible DOM Changes
Exercises
The Context API
Before: A Prop Drilling Example
The “Slots” Pattern
Using the React Context API
Provider and Consumer are a Pair
Context Holds No State
The Default Value
The “Render Props” Pattern
Provider Accepts One Value
Advanced Context Patterns
Turn the Consumer into a Higher-Order Component
Hold State in the Provider
The useContext Hook
Pass Actions Down Through Context
Example: Shopping Site
Break Into Components
Start Building
Arrow Function onClick
Is It Bad to Create Functions During Render?
Optimizing Components
Create ItemPage
Who Owns the Data?
Create the Item Component
Updating State Immutably
Back to the Code
Create the CartPage Component
Group and Count the Items
Pass the Grouped Items to CartPage
Modifying the Cart
Refactoring Item
Exercises
Where To Go From Here
API Calls and CRUD Operations
Testing
Webpack
ES6
Routing
Redux
TypeScript
On Boilerplate Projects
Thank You
Cover