From bd4e8db929aec7a9d2b72e9c2ccb3e211291f8aa Mon Sep 17 00:00:00 2001
From: Sylwia Vargas
Date: Tue, 2 Nov 2021 00:21:12 +0000
Subject: [PATCH] [Beta] Misc edits to text and examples
Co-authored-by: Dan Abramov
---
.../learn/choosing-the-state-structure.md | 1889 ++++++++++++-----
.../extracting-state-logic-into-a-reducer.md | 60 +-
beta/src/pages/learn/index.md | 28 +-
beta/src/pages/learn/managing-state.md | 138 +-
.../learn/passing-data-deeply-with-context.md | 272 ++-
.../learn/preserving-and-resetting-state.md | 112 +-
.../learn/reacting-to-input-with-state.md | 370 ++--
.../scaling-up-with-reducer-and-context.md | 150 +-
.../learn/sharing-state-between-components.md | 102 +-
9 files changed, 2030 insertions(+), 1091 deletions(-)
diff --git a/beta/src/pages/learn/choosing-the-state-structure.md b/beta/src/pages/learn/choosing-the-state-structure.md
index d0f3d1d9..a452c97c 100644
--- a/beta/src/pages/learn/choosing-the-state-structure.md
+++ b/beta/src/pages/learn/choosing-the-state-structure.md
@@ -26,7 +26,7 @@ When you write a component that holds some state, you'll have to make choices ab
4. **Avoid duplication in state.** When the same data is duplicated between multiple state variables, or within nested objects, it is difficult to keep them in sync. Reduce duplication when you can.
5. **Avoid deeply nested state.** Deeply hierarchical state is not very convenient to update. When possible, prefer to structure state in a flat way.
-The goal behind these principles is to *make state easy to update without introducing mistakes*. Removing redundant and duplicate data from state helps ensure that different pieces of it don't get out of sync. This is similar to how a database engineer might want to ["normalize" the database structure](https://docs.microsoft.com/en-us/office/troubleshoot/access/database-normalization-description) to reduce the chance of bugs. To paraphrase Albert Einstein, **"Make your state as simple as it can be--but no simpler."**
+The goal behind these principles is to *make state easy to update without introducing mistakes*. Removing redundant and duplicate data from state helps ensure that all its pieces stay in sync. This is similar to how a database engineer might want to ["normalize" the database structure](https://docs.microsoft.com/en-us/office/troubleshoot/access/database-normalization-description) to reduce the chance of bugs. To paraphrase Albert Einstein, **"Make your state as simple as it can be--but no simpler."**
Now let's see how these principles apply in action.
@@ -47,7 +47,7 @@ Or this?
const [position, setPosition] = useState({ x: 0, y: 0 });
```
-Technically, you can use either of these approaches. But **if some two state variables always change together, it might be a good idea to unify them into a single state variable**. Then you won't forget to always keep them in sync, like in this example where hovering updates both of the red dot's coordinates:
+Technically, you can use either of these approaches. But **if some two state variables always change together, it might be a good idea to unify them into a single state variable**. Then you won't forget to always keep them in sync, like in this example where moving the cursor updates both coordinates of the red dot:
@@ -96,20 +96,20 @@ Another case where you'll group data into an object or an array is when you don'
-If your state variable is an object, remember that you can't update only one field in it without explicitly copying the other fields. For example, you can't do `setPosition({ x: 100 })` in the above example because it would not have the `y` property at all! Instead, if you wanted to set `x` alone, you would either do `setPosition({ ...position, x: 100 })` or you would need to split them into two state variables, and do `setX(100)`.
+If your state variable is an object, remember that [you can't update only one field in it](/learn/updating-objects-in-state) without explicitly copying the other fields. For example, you can't do `setPosition({ x: 100 })` in the above example because it would not have the `y` property at all! Instead, if you wanted to set `x` alone, you would either do `setPosition({ ...position, x: 100 })`, or split them into two state variables and do `setX(100)`.
## Avoid contradictions in state
-Here is a form with `isSending` and `isSent` state variables:
+Here is a hotel feedback form with `isSending` and `isSent` state variables:
```js
import { useState } from 'react';
-export default function Chat() {
+export default function FeedbackForm() {
const [text, setText] = useState('');
const [isSending, setIsSending] = useState(false);
const [isSent, setIsSent] = useState(false);
@@ -123,16 +123,18 @@ export default function Chat() {
}
if (isSent) {
- return Sent!
+ return Thanks for feedback!
}
return (
+