Errata

Learning React

Errata for Learning React

Submit your own errata for this product.

The errata list is a list of errors and their corrections that were found after the product was released.

The following errata were submitted by our customers and have not yet been approved or disproved by the author or editor. They solely represent the opinion of the customer.

Color Key: Serious technical mistake Minor technical mistake Language or formatting error Typo Question Note Update

Version Location Description Submitted by Date submitted
N/A
Chapter 3, Section "Recursion"

At the end of the recursion section, there is a demonstration of each step of the deepPick function. The comment next to the function call (at the top of the code block) and the comment showing the result (at the bottom of the block) both say the result is "Deacon". But the function is fetching the "first" parameter of the name object, which is "Dan".

Chris Fincher  Jun 13, 2020 
N/A
Ch. 6, Section "Sending State Down a Component Tree"

The code block defining the StarRating function uses a function called onRate. onRate is not defined and added to the rest of the code until the next section.

Chris Fincher  Jun 23, 2020 
ePub Page Ch. 6
Roughly halfway through

export default function ColorList({ colors = [], onRemoveColor = f => f }) {
if (!colors.length) return <div>No Colors Listed. (Add a Color)</div>;

return (
colors.map(color => (
<Color key={color.id} {...color} onRemove={onRemoveColor} />
)
}
</div>
);
}

This code is missing a <div> after the return statement which is included in the source code here:

https://codesandbox.io/s/learning-react-color-organizer-2-iytxb?file=/src/ColorList.js

return (
<div>
{colors.map(color => (
<Color
key={color.id}
{...color}
onRemove={onRemoveColor}
onRate={onRateColor}
/>
))}
</div>
);


Charles Bolton  Jul 26, 2020 
ePub Page N/A
Chapter 6 section on Refs "Controlled components"

"In a controlled component, the from values are managed by React..."

should read "the form values are managed.."



Charles Bolton  Jul 27, 2020 
ePub Page N/A
Chapter 6 section "adding colors to state"

"Both the controlled form component and the uncontrolled from component pass"

from/form

Charles Bolton  Jul 27, 2020 
ePub Page N/A
Ch.8

formData.append("fullname", "Alex Banks");
forData.append("avatar", imgFile);

forData should be formData in second line.

The RepositoryReadme component should be handed in a different component.

handed => handled

Charles Bolton  Aug 01, 2020 
?
Ch 2, Destructuring Objects

The first code example assigns the destructured variables with `const { bread, meat } = ...

The subsequent text notes that the variables were declared with `let`, which they are in the following code sample.

Jon Riddle  Aug 05, 2020 
Ch. 1
Chapter 1, 6th paragraph

"We’re talking Uber, Twitter, Airbnb, and Twitter"

Twitter was mentioned twice.

Anonymous  Aug 14, 2020 
?
Ch 5 (JSX), Intro to Webpack, 3. CREATING THE WEBPACK BUILD

> The configuration file should be saved to the root folder of the project, right next to the index.js file

The reference to index.js should be index.html, given the directory structure laid out in Section 1 and the relative reference to "./src/index.js" in the code listing.

Jon Riddle  Aug 16, 2020 
?
Ch 5 (JSX), Intro to Webpack, 3. CREATING THE WEBPACK BUILD

The code listing for adding a build script to package.json is

"scripts": {
"build": "webpack --mode production"
},

but the previous command given was "npx webpack --mode development"

Is the production reference a typo, or is there a reason readers should use production in the build script but not when running by hand?

Jon Riddle  Aug 16, 2020 
?
Ch 5 (JSX), Intro to Webpack, Loading the Bundle

This section appears to contain some path inconsistencies:

1. "We exported the bundle to the dist folder." and the relative reference in the index.html code listing suggest that bundle.js should have been exported to ./dist, but the webpack.config.js code listing puts the bundle in ./dist/assets.

2. "The dist folder is where the index.html file should be placed.", but the directory structure given in 1. CREATE THE PROJECT shows index.html in the project root.

Jon Riddle  Aug 16, 2020 
ePub Page Chapter 2
Section: Object Literal Enhancement

The example overrides the function of the object itself when called mulitple times:
From:
// New
const skier = {
name,
sound,
powderYell() {
let yell = this.sound.toUpperCase();
console.log(`${yell} ${yell} ${yell}!!!`);
},
speed(mph) {
// !Next line overrides object function
this.speed = mph;
console.log("speed:", mph);
}
};
>> skiers.speed(12)
<< speed: 12
And then calling it again:
>> skiers.speed(12)
<< Uncaught TypeError: skiers.speed is not a function


Anonymous  Sep 04, 2020 
Ch 8
Chapter 8, Saving Data Locally

The code sample of the GitHubUser component that saves to localStorage only works in the sandbox because the login property given (moonhighway) differs in case from the GitHub username (MoonHighway). If the property is given with the same case as the login returned by GitHub, line 11 (in the sandbox; `if (data.login === login) return;`) returns as soon as data is loaded and it never saves to local storage, so data is always loaded from GitHub and much frustration ensues.

I got around this by adding a `saved: true` property to the data before saving locally and replacing the `if (data.login === login)` condition in the first useEffect with `if (data.saved)`.

Jon Riddle  Sep 06, 2020 
Ch 8
Chapter 8, Handling Multiple Requests

After the second code block in this section, the text reads 'In this case, the initial letter is "b"' - that should be "a".

Jon Riddle  Sep 06, 2020 
Ch 8
Ch 8, socket.io example

The socket.io code sample listens for a 'disconnecting' event - should be 'disconnect'.

Jon Riddle  Sep 13, 2020 
Ch 10
Ch 10, PropTypes

The code sample that is prefaced with "For example, if we used a boolean:" uses a string, but reports the error that would appear if the code had used a boolean as described.

Jon Riddle  Sep 27, 2020 
Ch 10
Ch 10, Flow

The two code samples under "This warning exists because if document.getElementById("root") returns null, the app will crash." appear to differ only in the inclusion of the conditional around .render(). What is the typecheck referred to in the second code sample?

Jon Riddle  Sep 27, 2020 
ePub Page N/A
Chapter 4, 2nd paragraph

The intro to Chapter 4 (How React Works) says:

To truly understand React, though, we need to understand its most atomic units: React elements. From there, we’ll get into React elements. From there, we’ll get into React components [...]

I think the 2nd sentence ("From there, we’ll get into React elements.") should be removed.


Enrique Matías Sánchez  Oct 06, 2020 
n/a
below Array.reduceRight

The explanation refers to an array called distinct. The array name is "unique".

Bríd Deely  Feb 12, 2021 
Chapter 10
Github repostitory links

In the "View the Code" links in the repository for Chapter 10, The links go to MoonHighway/learning-react/blob/master/chapter-10/in-the-flow (note the blob, and this happens on all view the code links) sends you to a 404 page.

Anonymous  Mar 15, 2023 
Chapter 2, Section: Async/Await
First Code Example

Error: getFakePerson() returns "undefined" in the console.

const getFakePerson = async () => {
let res = await fetch(someUrl);
let { results } = res.json();
console.log(results);
};

Using 'await' makes the variable 'res' a Response object.
However, when calling res.json(), the result is another Promise object.
I was unable to properly destructure the object because it was a Promise object.
Thus only "undefined" is logged in the console.
To fix this I had to add a second "await".

const getFakePerson = async () => {
let res = await fetch(someUrl);
let { results } = await res.json();
console.log(results);
};

This works because, fetch creates a Promise which is resolved, once the API returns data, into a Response.
Then res.json() creates a Promise which is *immediately* resolved into a Response object.
This response object can be destructured and the results properly logged to the console.

Tested in Firefox console.

Jonathan Claypool  Oct 08, 2023 
O'Reilly learning platform Page Chapter 2 > Object and Arrays > Destructuring Objects
In the code sample

The code uses const instead of let for destructuring the object into variables bread and meat. Subsequent para says ‘let’ is used. That is incorrect.

Jait Jacob  Dec 28, 2023 
PDF Page Page 245
Chapter 7 section "Rules to Follow with Hooks"

function Counter() {
const [count, setCount] = useState(0);
const [checked, toggle] =
useState(
count => (count < 5)
? undefined
: !c,
(count < 5) ? undefined
);
should be
function Counter() {
const [count, setCount] = useState(0);
const [checked, toggle] =
useState(
count => (count <= 5)
? undefined
: false
);

Wang Zhuojian  Feb 22, 2024 
Printed Page 1
Chapter 2, Page 14, Under Function returns, 2nd code example

Chapter 2, Page 14, Under Function returns, 2nd code example - arguments passed into function should be switched around as the function has been updated to accept firstName, then message as parameters re: `console.log(createCompliment("You're so cool", "Molly"))` should be `console.log(createCompliment("Molly", "You're so cool"))`

Ian  Jun 30, 2020 
Printed Page 1
6th paragraph

The sentence, "We're talking Uber, Twitter, Airbnb, and Twitter" has Twitter twice. Should replace one of the Twitters with Facebook or another huge company that uses React.

Anonymous  Jul 24, 2020 
PDF Page 2
P25

In the section of Async/Await, the getFakePerson function expression you write, I find that you missed a "await" before "res.json()". Otherwise the result in console of getFakePerson() is always undefined since the "res" is undefined before the await of fetch(...), so you cannot get "results" from res.json().

Edward Li  Mar 28, 2021 
6
chapter 6 Using Refs

Chapter 6
txtColor.current.value = "";
should be
hexColor.current.value = "";

Judy  Jun 15, 2020 
Printed, Mobi Page 9
Last paragraph

At "container = document.getElement...", it should be made clear that the element "container" is to be supplied in the HTML, or somewhere, otherwise it is just 'null', and appendChild() doesn't work.

John Wheater  Dec 31, 2020 
Printed Page 25
Both code examples in page 25

Missing 'await' operator before 'res.json();'
Without it, it returns 'undefined'.

const getFakePerson = async() => {
let res = await fetch("https://api.randomuser.me/?nat=US&results=1");
let { results } = res.json();
console.log(results);
};

getFakePerson();

Anonymous  Oct 23, 2020 
Printed Page 26
2nd code block

There is an extra closing parenthesis at the end of the getPeople(5) code block.

Current code block as printed in the book, which returns an "Unexpected token" error:

getPeople(5)
.then(members => console.log(members))
.catch(error => console.error(`getPeople failed: ${error.message}`))
);

Corrected code block:

getPeople(5)
.then(members => console.log(members))
.catch(error => console.error(`getPeople failed: ${error.message}`));



Milla Zagorski  Jan 02, 2021 
Printed, PDF, ePub Page 26
1st code listing: the getPeople function, line 9

In the `request.onload` function, if the `request.status` is not 200, we need to call `rejects(…)` instead of `reject(…)` on line 9.

Marius Butuc  Apr 20, 2021 
Printed Page 28
1st code block, the code output comment

The code output comment, as printed in the book, of "// Chile will take 7 days." might be more accurate and clear as: "// Santiago, Chile will take 7 days."

Milla Zagorski  Jan 02, 2021 
Printed Page 29
3rd code block

As printed in the book: "log("logging a message");" is missing the "timestamp" variable.

Milla Zagorski  Jan 02, 2021 
Printed Page 30
1st coe block

As printed in book, there are two missing equal signs and there is a closing curly bracket that should be a closing parenthesis:

const print(message) => log(message, new Date())

const log(message, timestamp) => console.log(`${timestamp.toString()}:
${message}`}

module.exports = {print, log}


Should be corrected as:

const print=(message) => log(message, new Date())

const log=(message, timestamp) => console.log(`${timestamp.toString()}:
${message}`)

module.exports = {print, log}

Milla Zagorski  Jan 02, 2021 
Printed Page 34
3rd paragraph

const string = "Restaurants in Hanalei";
const urlFriendly = "";
for (var i = 0; i < string.length; i++){
if (string[i] === " ") {
urlFriendly += "-";
}else{
urlFriendly += string[i];
}
}
console.log(urlFriendly);

urlFriendly is declared as const, but is assigned to in the for loop. This results in a "Uncaught TypeError: Assignment to constant variable."

Øivind Hagen  Aug 16, 2020 
Printed Page 53
3rd line

The code has `let time` twice (on lines 3 & 6 on page 53), which causes "SyntaxError: Identifier 'time' has already been declared".

The first `let time = "";` (on line 3) should be removed.

Anonymous  Jul 25, 2020 
Printed Page 55
Line 20 in prependZero code snippet

in prependZero declaration, key needs to be in brackets otherwise the "key" field is set, and not the actual key field name passed in (e.g. hours).

const prependZero = key => clockTime => ({
...clockTime,
key: clockTime[key] < 10 ? "0" + clockTime[key] : clockTime[key],
});

Key should be in brackets as it is a ES6 Computed Property Name.

[key]: clockTime[key] < 10 ? "0" + clockTime[key] : clockTime[key],

Anonymous  Jul 25, 2020 
Printed Page 57
2nd Paragraph, 5th sentence

Quote:
"To truly understand React, though, we need to understand its most atomic units: React elements. From there, we'll get into React elements. From there, we'll get into React components by looking ..."

Should read: "To truly understand React, though, we need to understand its most atomic units: React element. From there, we'll get into React components by looking ..."

since the 5th sentence in 2nd paragraph repeats "React elements".



Alex Kozin  Jul 17, 2021 
Printed Page 67
1st block of code

ReactDOM.render(
React.createElement(IngredientsList, null, null),
document.getElementById("root")
);

should be

ReactDOM.render(
React.createElement(IngredientsList, null, null),
document.getElementById("react-container")
);

Stefano G  Jan 27, 2021 
Other Digital Version 67
The code of function IngredientsList()

This is the corrected version of the code .I changed items for secretIngredients
function IngredientsList() {
return React.createElement(
"ul",
{ className: "ingredients" },
secretIngredients.map((ingredient, i) =>
React.createElement("li", { key: i }, ingredient)
)
);
}
The code in the book is:
function IngredientsList() {
return React.createElement(
"ul",
{ className: "ingredients" },
items.map((ingredient, i) =>
React.createElement("li", { key: i }, ingredient)
)
);
}

Gustavo Rojas  Dec 31, 2021 
Printed Page 75
in data array under ingredients

The salmon and whitefish measurement should be "lb" not "l lb".

{ name: "Salmon", amount: 1, measurement: "l lb" },

should be

{ name: "Salmon", amount: 1, measurement: "lb" },

Measurement "l lb" also appears on pages 78, 79, and 82. It is set correctly to "lb" on page 91.

Anonymous  Jul 26, 2020 
Printed Page 93
1st paragraph

The first paragraph on p. 93 says the bundle file path is ./dist/bundle.js, but the code at the bottom of p. 92 that creates the path using path.join has 'assets' dir in the path (./dist/assets/bundle.js).

Anonymous  Aug 01, 2020 
Printed Page 99
1st paragraph

“files” should be “fills” in the last sentence of the first paragraph.

“... that automatically files the stars ...”

Anonymous  Aug 01, 2020 
Printed Page 105
2nd paragraph

The word properties is repeated in “... other common properties properties to the entire star rating”

Anonymous  Aug 03, 2020 
PDF Page 125
Code example

Code example does not work (starting with data on prior page):

const secretIngredients = [
"1 cup unsalted butter",
"1 cup crunchy peanut butter",
"1 cup brown sugar",
"1 cup white sugar",
"2 eggs",
"2.5 cups all purpose flour",
"1 teaspoon baking powder",
"0.5 teaspoon salt"
];

function IngredientsList() {
return React.createElement(
"ul",
{ className: "ingredients" },
items.map((ingredient, i) =>
React.createElement("li", { key: i }, ingredient)
)
);
}

ReactDOM.render(
React.createElement(IngredientsList, { items: secretIngredients }, null),
document.getElementById("root")
);


Results in "ReferenceError: items is not defined."

Replacing the function with the following class works, but that hasn't yet been addressed in the material:

class IngredientsList extends React.Component {
render() {
return React.createElement("ul", {className: "ingredients"},
this.props.items.map((ingredient, i) =>
React.createElement("li", { key: i }, ingredient)
)
)
}
}

Anonymous  Mar 05, 2021 
PDF Page 125
Code Example

Another solution to the failed IngredientsList code example (see errata for PDF, page 125, Code Example, Mar 05, 2021), is to pass props into the component function, instead of replacing it with a class:

function IngredientsList(props) {
return React.createElement(
"ul",
{ className: "ingredients", items:secretIngredients },
props.items.map((ingredient, i) =>
React.createElement("li", { key: i }, ingredient)
)
);
}

Anonymous  Mar 05, 2021 
Printed Page 154
4th paragraph

The URL https://oreil.ly/1UNct redirects to https://chrome.google.com/webstore/detail/react-developer-tools/ which is a 404 Not Found page.

It should point to https://chrome.google.com/webstore/detail/react-developer-tools/fmkadmapgofadopljbjfkapdkoienihi?hl=en.

Anonymous  Nov 27, 2021 
Printed Page 177
1st header

The header, as printed in the book, of "Memozing Values" appears to be missing an "i" and might be corrected as "Memoizing Values".

Also, in the Table of Contents on page vi.

Milla Zagorski  Jan 02, 2021 
ePub Page 179
UserRepositories implementation

The UserRepositories implementation is not passing the login to the RepoMenu component. This breaks the RepositoryReadme component that happens a few pages later in the book and the react markdown will not load.

This technical error is also present in the example source code here:



https://codesandbox.io/s/cocky-fog-h6xde?file=/src/UserRepositories.js:347-363

Anonymous  Oct 01, 2020 
PDF Page 217
2nd code sample

3rd line of code:
const promise = new Promise...
is later referenced:
throw pending;

Should either be const pending... or throw promise

Ben Rand  Feb 02, 2021 
Printed Page 262
Code sample following 1st paragraph

The function for the Services component is missing the return keyword.

Jason Gero  Feb 27, 2022 
Printed Page 280
Code sample with NPM scripts

Folder name in which index.js file is placed is erroneously given as "server-build". It should be "build-server" to match what is in the webpack.server.js file on the previous page.

Jason Gero  Mar 06, 2022 
PDF Page 297
Handling Multiple Requests ~ p297

In this case, the initial letter is “b.” <------ (!!!) If the user invokes next, the
component will rerender, but this time, the value for letter will be
“b.”

Anonymous  Oct 05, 2020 
PDF Page 312
component UserRepositories from React Markdown example


In PDF and Sandbox :

...
<RepoMenu
repositories={data}
selected={repo}
onSelect={onSelect}
/> ...

|
|
|
V
If pass login - code work correctly

...
<RepoMenu
login={login} <-------- (!!!)
repositories={data}
selected={repo}
onSelect={onSelect}
/> ...



Anonymous  Oct 05, 2020