Introduction |
|
xxvii | |
|
|
1 | (10) |
|
React without a Build Toolchain |
|
|
1 | (6) |
|
Interactive "Hello, World" with Create React App and JSX |
|
|
7 | (2) |
|
|
9 | (2) |
|
Chapter 2 The Foundation Of React |
|
|
11 | (12) |
|
|
11 | (1) |
|
|
12 | (1) |
|
|
13 | (1) |
|
|
14 | (1) |
|
|
15 | (1) |
|
Composition vs. Inheritance |
|
|
15 | (1) |
|
|
16 | (1) |
|
|
17 | (1) |
|
|
17 | (1) |
|
|
18 | (1) |
|
|
18 | (1) |
|
|
19 | (1) |
|
|
19 | (1) |
|
React Is Not a Web Server |
|
|
20 | (1) |
|
React Is Not-a Programming Language |
|
|
20 | (1) |
|
React Is Not a Database Server |
|
|
21 | (1) |
|
React Is Not a Development Environment |
|
|
21 | (1) |
|
React Is Not the Perfect Solution to Every Problem |
|
|
21 | (1) |
|
|
21 | (2) |
|
|
23 | (20) |
|
|
23 | (7) |
|
|
30 | (1) |
|
|
30 | (1) |
|
|
31 | (1) |
|
Compilation vs. Transpilation |
|
|
31 | (1) |
|
|
31 | (1) |
|
|
31 | (2) |
|
Eliminating Browser Incompatibilities |
|
|
33 | (1) |
|
|
33 | (1) |
|
|
33 | (1) |
|
|
33 | (1) |
|
|
33 | (1) |
|
Preface Custom Attributes in DOM Elements with data- |
|
|
34 | (1) |
|
|
34 | (1) |
|
Use Curly Braces to Include Literal JavaScript |
|
|
35 | (1) |
|
Remember to Use Double Curly Braces with Objects |
|
|
35 | (1) |
|
Put Comments in Curly Braces |
|
|
35 | (1) |
|
When to Use JavaScript in JSX ( |
|
|
36 | (1) |
|
|
36 | (1) |
|
Conditional Rendering with if/else and Element Variables |
|
|
36 | (1) |
|
Conditional Rendering with the Operator |
|
|
37 | (1) |
|
Conditional Rendering with the Conditional Operator |
|
|
38 | (1) |
|
|
38 | (2) |
|
|
40 | (1) |
|
|
40 | (1) |
|
|
41 | (2) |
|
Chapter 4 All About Components |
|
|
43 | (62) |
|
|
43 | (1) |
|
|
44 | (1) |
|
Components Define Elements |
|
|
44 | (1) |
|
Elements Invoke Components |
|
|
45 | (2) |
|
|
47 | (1) |
|
|
47 | (5) |
|
|
52 | (1) |
|
|
52 | (1) |
|
|
52 | (2) |
|
|
54 | (2) |
|
|
56 | (1) |
|
|
56 | (1) |
|
|
56 | (1) |
|
|
56 | (1) |
|
|
57 | (11) |
|
Stepping through a React Class Component |
|
|
68 | (1) |
|
|
68 | (1) |
|
Importing React.Component |
|
|
68 | (1) |
|
|
69 | (1) |
|
|
69 | (2) |
|
Managing State in Class Components |
|
|
71 | (2) |
|
|
73 | (1) |
|
|
74 | (2) |
|
|
76 | (3) |
|
What Are Function Components? |
|
|
79 | (1) |
|
How to Write Function Components |
|
|
79 | (1) |
|
Optimizations and Function Component Shortcuts |
|
|
80 | (3) |
|
Managing State in Function Components |
|
|
83 | (1) |
|
Differences between Function and Class Components |
|
|
84 | (1) |
|
|
84 | (1) |
|
|
85 | (1) |
|
|
86 | (1) |
|
|
86 | (1) |
|
|
87 | (1) |
|
|
87 | (2) |
|
|
89 | (1) |
|
|
90 | (1) |
|
|
90 | (1) |
|
static getDerivedStateFromProps |
|
|
90 | (1) |
|
|
90 | (1) |
|
|
90 | (1) |
|
|
90 | (1) |
|
|
91 | (1) |
|
|
91 | (1) |
|
|
92 | (1) |
|
|
92 | (1) |
|
|
92 | (1) |
|
|
92 | (1) |
|
|
92 | (1) |
|
|
92 | (1) |
|
Improving Performance and Avoiding Errors |
|
|
92 | (1) |
|
|
93 | (3) |
|
|
96 | (1) |
|
|
97 | (1) |
|
|
98 | (1) |
|
|
98 | (1) |
|
|
98 | (2) |
|
|
100 | (1) |
|
|
101 | (1) |
|
|
101 | (1) |
|
|
102 | (1) |
|
|
103 | (1) |
|
|
103 | (1) |
|
|
103 | (1) |
|
|
104 | (1) |
|
|
105 | (18) |
|
Installation and Getting Started |
|
|
105 | (2) |
|
|
107 | (1) |
|
Working with the Component Tree |
|
|
108 | (2) |
|
|
110 | (1) |
|
Using the Search Input Box |
|
|
110 | (1) |
|
Using Regular Expressions |
|
|
110 | (2) |
|
|
112 | (2) |
|
|
114 | (1) |
|
Editing Component Data in DevTools |
|
|
114 | (4) |
|
Working with Additional DevTools Functionality |
|
|
118 | (1) |
|
|
119 | (2) |
|
|
121 | (2) |
|
Chapter 6 React Data Flow |
|
|
123 | (76) |
|
|
123 | (1) |
|
Understanding One-Way Data Flow |
|
|
124 | (1) |
|
|
125 | (1) |
|
|
126 | (1) |
|
|
126 | (1) |
|
Props Can Be Any Data Type |
|
|
126 | (1) |
|
|
127 | (2) |
|
Validating Incoming Props with PropTypes |
|
|
129 | (1) |
|
|
130 | (1) |
|
Getting Started with PropTypes |
|
|
131 | (2) |
|
What Can PropTypes Validate? |
|
|
133 | (8) |
|
|
141 | (4) |
|
|
145 | (1) |
|
|
146 | (1) |
|
|
146 | (1) |
|
Initializing state in Class Components |
|
|
146 | (1) |
|
Initializing State in Function Components |
|
|
147 | (2) |
|
The Difference between state and props |
|
|
149 | (1) |
|
|
149 | (1) |
|
Updating a Class Component's state with setState |
|
|
150 | (4) |
|
Updating state with Function Components |
|
|
154 | (7) |
|
|
161 | (1) |
|
Building the Reminders App |
|
|
161 | (7) |
|
|
168 | (1) |
|
|
168 | (2) |
|
|
170 | (7) |
|
|
177 | (6) |
|
|
183 | (5) |
|
Implementing the isComplete Changing Functionality |
|
|
188 | (2) |
|
Converting to Class Components |
|
|
190 | (8) |
|
|
198 | (1) |
|
|
199 | (22) |
|
|
199 | (2) |
|
|
201 | (1) |
|
Using Event Listener Attributes |
|
|
202 | (1) |
|
|
203 | (1) |
|
|
204 | (7) |
|
|
211 | (1) |
|
Writing Inline Event Handlers |
|
|
211 | (1) |
|
Writing Event Handlers in Function Components |
|
|
212 | (1) |
|
Writing Event Handlers in Class Components |
|
|
213 | (1) |
|
Binding Event Handler Functions |
|
|
214 | (1) |
|
|
215 | (1) |
|
|
216 | (2) |
|
Passing Data to Event Handlers |
|
|
218 | (1) |
|
|
219 | (2) |
|
|
221 | (12) |
|
|
221 | (1) |
|
Controlled Inputs vs. Uncontrolled Inputs |
|
|
222 | (1) |
|
Updating a Controlled Input |
|
|
223 | (1) |
|
Controlling an Input in a Function Component |
|
|
224 | (1) |
|
Controlling an Input in a Class Component |
|
|
224 | (2) |
|
|
226 | (2) |
|
Using Uncontrolled Inputs |
|
|
228 | (1) |
|
Using Different Form Elements |
|
|
229 | (1) |
|
Controlling the Input Element |
|
|
230 | (1) |
|
|
230 | (1) |
|
Controlling a Select Element |
|
|
231 | (1) |
|
Preventing Default Actions |
|
|
231 | (1) |
|
|
232 | (1) |
|
|
233 | (10) |
|
|
233 | (1) |
|
How to Create a Ref in a Class Component |
|
|
234 | (1) |
|
How to Create a Ref in a Function Component |
|
|
234 | (1) |
|
|
234 | (2) |
|
|
236 | (2) |
|
|
238 | (1) |
|
|
238 | (1) |
|
|
239 | (1) |
|
|
239 | (1) |
|
Automatically Selecting Text |
|
|
239 | (2) |
|
Controlling Media Playback |
|
|
241 | (1) |
|
|
241 | (1) |
|
|
242 | (1) |
|
|
243 | (14) |
|
|
243 | (1) |
|
Importing CSS into the HTML File |
|
|
244 | (1) |
|
Using Plain Old CSS in Components |
|
|
245 | (2) |
|
|
247 | (1) |
|
|
248 | (1) |
|
|
249 | (1) |
|
Why Not to Use Inline Styles |
|
|
249 | (1) |
|
Improving Inline Styles with Style Modules |
|
|
249 | (1) |
|
|
250 | (1) |
|
|
251 | (1) |
|
Advanced CSS Modules Functionality |
|
|
252 | (1) |
|
|
252 | (1) |
|
|
252 | (1) |
|
CSS-in-JS and Styled Components |
|
|
253 | (2) |
|
|
255 | (2) |
|
Chapter 11 Introducing Hooks |
|
|
257 | (32) |
|
|
257 | (1) |
|
Why Were Hooks Introduced? |
|
|
257 | (2) |
|
|
259 | (1) |
|
|
259 | (1) |
|
Managing State with useState |
|
|
260 | (2) |
|
Setting the Initial State |
|
|
262 | (1) |
|
Using the Setter Function |
|
|
262 | (1) |
|
Passing a Value to a Setter |
|
|
263 | (1) |
|
Passing a Function to a Setter |
|
|
263 | (1) |
|
Setter Function Value Comparison |
|
|
264 | (1) |
|
Hooking into the Lifecycle with useEffect |
|
|
264 | (1) |
|
Using the Default useEffect Behavior |
|
|
265 | (1) |
|
Cleaning Up After Effects |
|
|
265 | (1) |
|
|
266 | (4) |
|
Running Asynchronous Code with useEffect |
|
|
270 | (2) |
|
Subscribing to Global Data with useContext |
|
|
272 | (1) |
|
Combining Logic and State with useReducer |
|
|
273 | (2) |
|
Memoized Callbacks with useCallback |
|
|
275 | (3) |
|
Caching Computed Values with useMemo |
|
|
278 | (1) |
|
Solving Unnecessary Renders |
|
|
278 | (1) |
|
Solving Performance Problems |
|
|
279 | (1) |
|
Accessing Children Imperatively with useRef |
|
|
279 | (1) |
|
Customizing Exposed Values with uselmperativeHandle |
|
|
280 | (1) |
|
Updating the DOM Synchronously with useLayoutEffect |
|
|
281 | (1) |
|
|
281 | (2) |
|
Labeling Custom Hooks with useDebugValue |
|
|
283 | (2) |
|
Finding and Using Custom Hooks |
|
|
285 | (1) |
|
|
285 | (1) |
|
|
286 | (1) |
|
|
286 | (1) |
|
|
286 | (1) |
|
|
287 | (1) |
|
|
287 | (1) |
|
|
288 | (1) |
|
|
288 | (1) |
|
|
288 | (1) |
|
|
289 | (30) |
|
|
289 | (2) |
|
How Routing Works in React |
|
|
291 | (2) |
|
|
293 | (1) |
|
Installing and Importing react-router-dom |
|
|
293 | (1) |
|
|
294 | (1) |
|
|
294 | (1) |
|
Using the Router Component |
|
|
295 | (1) |
|
|
296 | (1) |
|
Internal Linking with Link |
|
|
296 | (2) |
|
Internal Navigation with NavLink |
|
|
298 | (4) |
|
Automatic Linking with Redirect |
|
|
302 | (1) |
|
|
302 | (2) |
|
Restricting Path Matching |
|
|
304 | (1) |
|
|
304 | (1) |
|
|
305 | (1) |
|
|
306 | (1) |
|
|
307 | (1) |
|
Rendering a Default Route |
|
|
308 | (1) |
|
|
308 | (1) |
|
Behind the Scenes: location, history, and match |
|
|
309 | (1) |
|
|
310 | (3) |
|
|
313 | (1) |
|
|
313 | (4) |
|
|
317 | (1) |
|
|
317 | (1) |
|
|
317 | (1) |
|
|
317 | (1) |
|
|
317 | (1) |
|
|
318 | (1) |
|
Chapter 13 Error Boundaries |
|
|
319 | (20) |
|
|
319 | (1) |
|
What Is an Error Boundary? |
|
|
320 | (3) |
|
Implementing an Error Boundary |
|
|
323 | (1) |
|
Building Your Own ErrorBoundary Component |
|
|
323 | (1) |
|
getDerivedStateFromErrors Is a Static Method |
|
|
324 | (1) |
|
getDerivedStateFromErrors Runs During the Render Phase |
|
|
325 | (1) |
|
getDerivedStateFromErrors Receives the Error as a Parameter |
|
|
325 | (1) |
|
getDerivedStateFromErrors Should Return an Object for |
|
|
|
|
325 | (1) |
|
|
326 | (1) |
|
Logging Errors with ComponentDidCatch() |
|
|
327 | (1) |
|
|
328 | (5) |
|
|
333 | (1) |
|
Installing a Pre-Built ErrorBoundary Component |
|
|
334 | (2) |
|
What Can't an Error Boundary Catch? |
|
|
336 | (1) |
|
Catching Errors in Error Boundaries with try/catch |
|
|
336 | (1) |
|
Catching Errors in Event Handlers with react-error-boundary |
|
|
337 | (1) |
|
|
338 | (1) |
|
Chapter 14 Deploying React |
|
|
339 | (12) |
|
|
339 | (1) |
|
|
339 | (1) |
|
|
340 | (1) |
|
Examining the build Directory |
|
|
340 | (1) |
|
|
341 | (1) |
|
|
342 | (1) |
|
|
342 | (1) |
|
|
343 | (1) |
|
How Is a Deployed App Different? |
|
|
343 | (1) |
|
Development Mode vs. Production |
|
|
343 | (1) |
|
|
344 | (1) |
|
|
344 | (1) |
|
|
345 | (1) |
|
|
345 | (2) |
|
Enabling Routing with Netlify |
|
|
347 | (1) |
|
Enabling Custom Domains and HTTPS |
|
|
348 | (1) |
|
|
349 | (2) |
|
Chapter 15 Initialize A React Project From Scratch |
|
|
351 | (18) |
|
Building Your Own Toolchain |
|
|
351 | (1) |
|
Initializing Your Project |
|
|
352 | (1) |
|
|
352 | (1) |
|
|
353 | (1) |
|
|
353 | (1) |
|
|
354 | (3) |
|
|
357 | (1) |
|
|
358 | (1) |
|
|
358 | (1) |
|
Automating Your Build Process |
|
|
358 | (1) |
|
|
359 | (1) |
|
Development Server and Hot Reloading |
|
|
360 | (1) |
|
|
360 | (1) |
|
Installing and Configuring ESLint |
|
|
360 | (1) |
|
|
361 | (1) |
|
|
362 | (1) |
|
|
363 | (1) |
|
|
364 | (1) |
|
Structuring Your Source Directory |
|
|
365 | (1) |
|
|
366 | (1) |
|
|
367 | (1) |
|
|
367 | (2) |
|
Chapter 16 Fetching And Caching Data |
|
|
369 | (18) |
|
Asynchronous Code: It's All About Timing |
|
|
369 | (1) |
|
|
370 | (4) |
|
Where to Run Async Code in React |
|
|
374 | (2) |
|
|
376 | (1) |
|
|
377 | (1) |
|
|
377 | (2) |
|
|
379 | (1) |
|
|
379 | (1) |
|
|
380 | (1) |
|
When Not to Use Web Storage |
|
|
380 | (1) |
|
Web Storage Is Synchronous |
|
|
380 | (1) |
|
Working with localStorage |
|
|
381 | (1) |
|
Storing Data with localStorage |
|
|
381 | (1) |
|
Reading Data from localStorage |
|
|
382 | (2) |
|
Removing Data from localStorage |
|
|
384 | (1) |
|
|
385 | (2) |
|
|
387 | (12) |
|
|
387 | (1) |
|
How Context API Solves the Problem |
|
|
388 | (1) |
|
|
388 | (1) |
|
|
389 | (1) |
|
|
390 | (1) |
|
Using Context in a Class Component |
|
|
390 | (1) |
|
Using Context in a Function Component |
|
|
391 | (1) |
|
Common Use Cases for Context |
|
|
391 | (1) |
|
|
392 | (1) |
|
Composition as an Alternative to Context |
|
|
392 | (4) |
|
Example App: User Preferences |
|
|
396 | (2) |
|
|
398 | (1) |
|
|
399 | (14) |
|
|
399 | (1) |
|
|
399 | (4) |
|
Why Not Just Render Multiple Component Trees? |
|
|
403 | (1) |
|
|
403 | (1) |
|
Rendering and Interacting with a Modal Dialog |
|
|
404 | (5) |
|
Managing Keyboard Focus with Modals |
|
|
409 | (2) |
|
|
411 | (2) |
|
Chapter 19 Accessibility In React |
|
|
413 | (12) |
|
Why Is Accessibility Important? |
|
|
413 | (1) |
|
|
414 | (1) |
|
Web Content Accessibility Guidelines (WCAG) |
|
|
414 | (1) |
|
Web Accessibility Initiative - Accessible Rich Internet |
|
|
|
|
415 | (1) |
|
Implementing Accessibility in React Components |
|
|
415 | (1) |
|
|
416 | (1) |
|
|
416 | (1) |
|
|
417 | (1) |
|
|
418 | (1) |
|
|
418 | (1) |
|
Managing Focus Programmatically |
|
|
419 | (1) |
|
|
420 | (1) |
|
Media Queries in Included CSS |
|
|
421 | (1) |
|
|
422 | (1) |
|
|
422 | (3) |
|
|
425 | (12) |
|
|
425 | (1) |
|
|
426 | (1) |
|
|
426 | (1) |
|
|
427 | (1) |
|
|
427 | (1) |
|
|
428 | (1) |
|
|
428 | (1) |
|
|
428 | (1) |
|
|
428 | (1) |
|
|
429 | (1) |
|
|
430 | (1) |
|
|
430 | (2) |
|
|
432 | (1) |
|
|
433 | (1) |
|
|
434 | (1) |
|
|
434 | (1) |
|
|
434 | (1) |
|
|
435 | (1) |
|
Useful Links and Resources |
|
|
435 | (1) |
|
|
436 | (1) |
Index |
|
437 | |