From a220bb3f21170210fb37375f349c943150a5364d Mon Sep 17 00:00:00 2001
From: k8o <61353435+k35o@users.noreply.github.com>
Date: Thu, 22 Aug 2024 16:46:36 +0900
Subject: [PATCH 1/4] docs: replace check mark emoji to check mark button emoji
(#7121)
---
.../blog/2023/03/16/introducing-react-dev.md | 4 +--
src/content/learn/conditional-rendering.md | 32 +++++++++----------
src/content/learn/describing-the-ui.md | 2 +-
3 files changed, 19 insertions(+), 19 deletions(-)
diff --git a/src/content/blog/2023/03/16/introducing-react-dev.md b/src/content/blog/2023/03/16/introducing-react-dev.md
index 2498f40dce..c4da2b61f0 100644
--- a/src/content/blog/2023/03/16/introducing-react-dev.md
+++ b/src/content/blog/2023/03/16/introducing-react-dev.md
@@ -269,7 +269,7 @@ Use the conditional operator (`cond ? a : b`) to render a ❌ if `isPacked` isn
function Item({ name, isPacked }) {
return (
- {name} {isPacked && '✔'}
+ {name} {isPacked && '✅'}
);
}
@@ -307,7 +307,7 @@ export default function PackingList() {
function Item({ name, isPacked }) {
return (
- {name} {isPacked ? '✔' : '❌'}
+ {name} {isPacked ? '✅' : '❌'}
);
}
diff --git a/src/content/learn/conditional-rendering.md b/src/content/learn/conditional-rendering.md
index 895d610d33..95be5d2e01 100644
--- a/src/content/learn/conditional-rendering.md
+++ b/src/content/learn/conditional-rendering.md
@@ -52,13 +52,13 @@ export default function PackingList() {
-Notice that some of the `Item` components have their `isPacked` prop set to `true` instead of `false`. You want to add a checkmark (✔) to packed items if `isPacked={true}`.
+Notice that some of the `Item` components have their `isPacked` prop set to `true` instead of `false`. You want to add a checkmark (✅) to packed items if `isPacked={true}`.
You can write this as an [`if`/`else` statement](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/if...else) like so:
```js
if (isPacked) {
- return {name} ✔;
+ return {name} ✅;
}
return {name};
```
@@ -70,7 +70,7 @@ If the `isPacked` prop is `true`, this code **returns a different JSX tree.** Wi
```js
function Item({ name, isPacked }) {
if (isPacked) {
- return {name} ✔;
+ return {name} ✅;
}
return {name};
}
@@ -159,7 +159,7 @@ In practice, returning `null` from a component isn't common because it might sur
In the previous example, you controlled which (if any!) JSX tree would be returned by the component. You may already have noticed some duplication in the render output:
```js
-{name} ✔
+{name} ✅
```
is very similar to
@@ -172,7 +172,7 @@ Both of the conditional branches return `...`:
```js
if (isPacked) {
- return {name} ✔;
+ return {name} ✅;
}
return {name};
```
@@ -187,7 +187,7 @@ Instead of this:
```js
if (isPacked) {
- return {name} ✔;
+ return {name} ✅;
}
return {name};
```
@@ -197,12 +197,12 @@ You can write this:
```js
return (
- {isPacked ? name + ' ✔' : name}
+ {isPacked ? name + ' ✅' : name}
);
```
-You can read it as *"if `isPacked` is true, then (`?`) render `name + ' ✔'`, otherwise (`:`) render `name`"*.
+You can read it as *"if `isPacked` is true, then (`?`) render `name + ' ✅'`, otherwise (`:`) render `name`"*.
@@ -222,7 +222,7 @@ function Item({ name, isPacked }) {
{isPacked ? (
- {name + ' ✔'}
+ {name + ' ✅'}
) : (
name
@@ -265,7 +265,7 @@ Another common shortcut you'll encounter is the [JavaScript logical AND (`&&`) o
```js
return (
- {name} {isPacked && '✔'}
+ {name} {isPacked && '✅'}
);
```
@@ -280,7 +280,7 @@ Here it is in action:
function Item({ name, isPacked }) {
return (
- {name} {isPacked && '✔'}
+ {name} {isPacked && '✅'}
);
}
@@ -337,7 +337,7 @@ Use an `if` statement to reassign a JSX expression to `itemContent` if `isPacked
```js
if (isPacked) {
- itemContent = name + " ✔";
+ itemContent = name + " ✅";
}
```
@@ -357,7 +357,7 @@ This style is the most verbose, but it's also the most flexible. Here it is in a
function Item({ name, isPacked }) {
let itemContent = name;
if (isPacked) {
- itemContent = name + " ✔";
+ itemContent = name + " ✅";
}
return (
@@ -401,7 +401,7 @@ function Item({ name, isPacked }) {
if (isPacked) {
itemContent = (
- {name + " ✔"}
+ {name + " ✅"}
);
}
@@ -464,7 +464,7 @@ Use the conditional operator (`cond ? a : b`) to render a ❌ if `isPacked` isn
function Item({ name, isPacked }) {
return (
- {name} {isPacked && '✔'}
+ {name} {isPacked && '✅'}
);
}
@@ -502,7 +502,7 @@ export default function PackingList() {
function Item({ name, isPacked }) {
return (
- {name} {isPacked ? '✔' : '❌'}
+ {name} {isPacked ? '✅' : '❌'}
);
}
diff --git a/src/content/learn/describing-the-ui.md b/src/content/learn/describing-the-ui.md
index ce49b85c8f..34ee0c01a1 100644
--- a/src/content/learn/describing-the-ui.md
+++ b/src/content/learn/describing-the-ui.md
@@ -327,7 +327,7 @@ In this example, the JavaScript `&&` operator is used to conditionally render a
function Item({ name, isPacked }) {
return (
- {name} {isPacked && '✔'}
+ {name} {isPacked && '✅'}
);
}
From b5f28b48441e7e46c11ba066110a3c952c33c4ba Mon Sep 17 00:00:00 2001
From: Bartosz Klonowski <70535775+BartoszKlonowski@users.noreply.github.com>
Date: Fri, 23 Aug 2024 14:21:11 +0200
Subject: [PATCH 2/4] Redirect lists-and-keys to rendering-lists describing key
(#7120)
---
vercel.json | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/vercel.json b/vercel.json
index eac0efb9c4..8b0546e372 100644
--- a/vercel.json
+++ b/vercel.json
@@ -24,6 +24,11 @@
"destination": "/learn/rendering-lists#keeping-list-items-in-order-with-key",
"permanent": false
},
+ {
+ "source": "/docs/lists-and-keys",
+ "destination": "/learn/rendering-lists#keeping-list-items-in-order-with-key",
+ "permanent": false
+ },
{
"source": "/link/invalid-hook-call",
"destination": "/warnings/invalid-hook-call-warning",
From 7d50c3ffd4df2dc7903f4e41069653a456a9c223 Mon Sep 17 00:00:00 2001
From: Bartosz Klonowski <70535775+BartoszKlonowski@users.noreply.github.com>
Date: Sun, 25 Aug 2024 22:32:42 +0200
Subject: [PATCH 3/4] Emphasize the second problem paragraph with chain of
effects example (#7108)
* Emphasize the second problem acapit with chain of effects example
* Replace 'One' with 'First' to keep problems counting consistent
---
src/content/learn/you-might-not-need-an-effect.md | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/content/learn/you-might-not-need-an-effect.md b/src/content/learn/you-might-not-need-an-effect.md
index 66cdc31177..27031720d5 100644
--- a/src/content/learn/you-might-not-need-an-effect.md
+++ b/src/content/learn/you-might-not-need-an-effect.md
@@ -408,9 +408,9 @@ function Game() {
There are two problems with this code.
-One problem is that it is very inefficient: the component (and its children) have to re-render between each `set` call in the chain. In the example above, in the worst case (`setCard` → render → `setGoldCardCount` → render → `setRound` → render → `setIsGameOver` → render) there are three unnecessary re-renders of the tree below.
+First problem is that it is very inefficient: the component (and its children) have to re-render between each `set` call in the chain. In the example above, in the worst case (`setCard` → render → `setGoldCardCount` → render → `setRound` → render → `setIsGameOver` → render) there are three unnecessary re-renders of the tree below.
-Even if it weren't slow, as your code evolves, you will run into cases where the "chain" you wrote doesn't fit the new requirements. Imagine you are adding a way to step through the history of the game moves. You'd do it by updating each state variable to a value from the past. However, setting the `card` state to a value from the past would trigger the Effect chain again and change the data you're showing. Such code is often rigid and fragile.
+The second problem is that even if it weren't slow, as your code evolves, you will run into cases where the "chain" you wrote doesn't fit the new requirements. Imagine you are adding a way to step through the history of the game moves. You'd do it by updating each state variable to a value from the past. However, setting the `card` state to a value from the past would trigger the Effect chain again and change the data you're showing. Such code is often rigid and fragile.
In this case, it's better to calculate what you can during rendering, and adjust the state in the event handler:
From dea3597b5483dfab7f477fbb418144c673fa142e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=B8=85=E7=A7=8B?=
Date: Mon, 26 Aug 2024 11:35:05 +0800
Subject: [PATCH 4/4] fix conflicts
---
src/content/learn/conditional-rendering.md | 12 ++----------
src/content/learn/you-might-not-need-an-effect.md | 10 ++--------
2 files changed, 4 insertions(+), 18 deletions(-)
diff --git a/src/content/learn/conditional-rendering.md b/src/content/learn/conditional-rendering.md
index d368800ea6..9c41604bc6 100644
--- a/src/content/learn/conditional-rendering.md
+++ b/src/content/learn/conditional-rendering.md
@@ -54,11 +54,7 @@ export default function PackingList() {
-<<<<<<< HEAD
-需要注意的是,有些 `Item` 组件的 `isPacked` 属性是被设为 `true` 而不是 `false`。你可以在那些满足 `isPacked={true}` 条件的物品旁加上一个勾选符号(✔)。
-=======
-Notice that some of the `Item` components have their `isPacked` prop set to `true` instead of `false`. You want to add a checkmark (✅) to packed items if `isPacked={true}`.
->>>>>>> 7d50c3ffd4df2dc7903f4e41069653a456a9c223
+需要注意的是,有些 `Item` 组件的 `isPacked` 属性是被设为 `true` 而不是 `false`。你可以在那些满足 `isPacked={true}` 条件的物品旁加上一个勾选符号(✅)。
你可以用 [if/else 语句](https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Statements/if...else) 去判断:
@@ -208,11 +204,7 @@ return (
);
```
-<<<<<<< HEAD
-你可以认为,*“如果 `isPacked` 为 true 时,则(`?`)渲染 `name + ' ✔'`,否则(`:`)渲染 `name`。”*
-=======
-You can read it as *"if `isPacked` is true, then (`?`) render `name + ' ✅'`, otherwise (`:`) render `name`"*.
->>>>>>> 7d50c3ffd4df2dc7903f4e41069653a456a9c223
+你可以认为,*“如果 `isPacked` 为 true 时,则(`?`)渲染 `name + ' ✅'`,否则(`:`)渲染 `name`。”*
diff --git a/src/content/learn/you-might-not-need-an-effect.md b/src/content/learn/you-might-not-need-an-effect.md
index ef7acda80a..af2e16f2d1 100644
--- a/src/content/learn/you-might-not-need-an-effect.md
+++ b/src/content/learn/you-might-not-need-an-effect.md
@@ -408,15 +408,9 @@ function Game() {
这段代码里有两个问题。
-<<<<<<< HEAD
-一个问题是它非常低效:在链式的每个 `set` 调用之间,组件(及其子组件)都不得不重新渲染。在上面的例子中,在最坏的情况下(`setCard` → 渲染 → `setGoldCardCount` → 渲染 → `setRound` → 渲染 → `setIsGameOver` → 渲染)有三次不必要的重新渲染。
+第一个问题是它非常低效:在链式的每个 `set` 调用之间,组件(及其子组件)都不得不重新渲染。在上面的例子中,在最坏的情况下(`setCard` → 渲染 → `setGoldCardCount` → 渲染 → `setRound` → 渲染 → `setIsGameOver` → 渲染)有三次不必要的重新渲染。
-即使不考虑渲染效率问题,随着代码不断扩展,你会遇到这条 “链式” 调用不符合新需求的情况。试想一下,你现在需要添加一种方法来回溯游戏的历史记录,可以通过更新每个 state 变量到之前的值来实现。然而,将 `card` 设置为之前的的某个值会再次触发 Effect 链并更改你正在显示的数据。这样的代码往往是僵硬而脆弱的。
-=======
-First problem is that it is very inefficient: the component (and its children) have to re-render between each `set` call in the chain. In the example above, in the worst case (`setCard` → render → `setGoldCardCount` → render → `setRound` → render → `setIsGameOver` → render) there are three unnecessary re-renders of the tree below.
-
-The second problem is that even if it weren't slow, as your code evolves, you will run into cases where the "chain" you wrote doesn't fit the new requirements. Imagine you are adding a way to step through the history of the game moves. You'd do it by updating each state variable to a value from the past. However, setting the `card` state to a value from the past would trigger the Effect chain again and change the data you're showing. Such code is often rigid and fragile.
->>>>>>> 7d50c3ffd4df2dc7903f4e41069653a456a9c223
+第二个问题是,即使不考虑渲染效率问题,随着代码不断扩展,你会遇到这条 “链式” 调用不符合新需求的情况。试想一下,你现在需要添加一种方法来回溯游戏的历史记录,可以通过更新每个 state 变量到之前的值来实现。然而,将 `card` 设置为之前的的某个值会再次触发 Effect 链并更改你正在显示的数据。这样的代码往往是僵硬而脆弱的。
在这个例子中,更好的做法是:尽可能在渲染期间进行计算,以及在事件处理函数中调整 state: