Skip to content

Commit 992b062

Browse files
authored
Merge pull request #967 from reactjs/sync-7d50c3ff
Sync with react.dev @ 7d50c3f
2 parents a953d8a + b143938 commit 992b062

File tree

5 files changed

+26
-21
lines changed

5 files changed

+26
-21
lines changed

src/content/blog/2023/03/16/introducing-react-dev.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ Use the conditional operator (`cond ? a : b`) to render a ❌ if `isPacked` isn
269269
function Item({ name, isPacked }) {
270270
return (
271271
<li className="item">
272-
{name} {isPacked && ''}
272+
{name} {isPacked && ''}
273273
</li>
274274
);
275275
}
@@ -307,7 +307,7 @@ export default function PackingList() {
307307
function Item({ name, isPacked }) {
308308
return (
309309
<li className="item">
310-
{name} {isPacked ? '' : ''}
310+
{name} {isPacked ? '' : ''}
311311
</li>
312312
);
313313
}

src/content/learn/conditional-rendering.md

+16-16
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ export default function PackingList() {
5252
</Sandpack>
5353
5454

55-
Обратите внимание, что у некоторых компонентов `Item` проп `isPacked` имеет значение `true`, вместо значения `false`. Если `isPacked={true}`, вы хотите добавить галочку() к упакованным вещам.
55+
Обратите внимание, что у некоторых компонентов `Item` проп `isPacked` имеет значение `true`, вместо значения `false`. Если `isPacked={true}`, вы хотите добавить галочку() к упакованным вещам.
5656

5757
Можно реализовать это с помощью [управляющей конструкции `if`/`else`](https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Statements/if...) таким образом:
5858

5959
```js
6060
if (isPacked) {
61-
return <li className="item">{name} </li>;
61+
return <li className="item">{name} </li>;
6262
}
6363
return <li className="item">{name}</li>;
6464
```
@@ -70,7 +70,7 @@ return <li className="item">{name}</li>;
7070
```js
7171
function Item({ name, isPacked }) {
7272
if (isPacked) {
73-
return <li className="item">{name} </li>;
73+
return <li className="item">{name} </li>;
7474
}
7575
return <li className="item">{name}</li>;
7676
}
@@ -159,7 +159,7 @@ export default function PackingList() {
159159
В предыдущем примере вы контролировали, какое JSX дерево будет возвращено компонентом (если вообще будет!). Возможно, вы уже заметили некоторое дублирование в выводе рендера:
160160

161161
```js
162-
<li className="item">{name} </li>
162+
<li className="item">{name} </li>
163163
```
164164

165165
очень похоже на
@@ -172,7 +172,7 @@ export default function PackingList() {
172172

173173
```js
174174
if (isPacked) {
175-
return <li className="item">{name} </li>;
175+
return <li className="item">{name} </li>;
176176
}
177177
return <li className="item">{name}</li>;
178178
```
@@ -187,7 +187,7 @@ return <li className="item">{name}</li>;
187187

188188
```js
189189
if (isPacked) {
190-
return <li className="item">{name} </li>;
190+
return <li className="item">{name} </li>;
191191
}
192192
return <li className="item">{name}</li>;
193193
```
@@ -197,12 +197,12 @@ return <li className="item">{name}</li>;
197197
```js
198198
return (
199199
<li className="item">
200-
{isPacked ? name + ' ' : name}
200+
{isPacked ? name + ' ' : name}
201201
</li>
202202
);
203203
```
204204

205-
Вы можете читать это как *"если `isPacked` равно true, тогда (`?`) рендерим `name + ' '`, в противном случае (`:`) рендерим `name`"*.
205+
Вы можете читать это как *"если `isPacked` равно true, тогда (`?`) рендерим `name + ' '`, в противном случае (`:`) рендерим `name`"*.
206206

207207
<DeepDive>
208208

@@ -222,7 +222,7 @@ function Item({ name, isPacked }) {
222222
<li className="item">
223223
{isPacked ? (
224224
<del>
225-
{name + ' '}
225+
{name + ' '}
226226
</del>
227227
) : (
228228
name
@@ -265,7 +265,7 @@ export default function PackingList() {
265265
```js
266266
return (
267267
<li className="item">
268-
{name} {isPacked && ''}
268+
{name} {isPacked && ''}
269269
</li>
270270
);
271271
```
@@ -280,7 +280,7 @@ return (
280280
function Item({ name, isPacked }) {
281281
return (
282282
<li className="item">
283-
{name} {isPacked && ''}
283+
{name} {isPacked && ''}
284284
</li>
285285
);
286286
}
@@ -337,7 +337,7 @@ let itemContent = name;
337337

338338
```js
339339
if (isPacked) {
340-
itemContent = name + ' ';
340+
itemContent = name + ' ';
341341
}
342342
```
343343

@@ -357,7 +357,7 @@ if (isPacked) {
357357
function Item({ name, isPacked }) {
358358
let itemContent = name;
359359
if (isPacked) {
360-
itemContent = name + ' ';
360+
itemContent = name + ' ';
361361
}
362362
return (
363363
<li className="item">
@@ -401,7 +401,7 @@ function Item({ name, isPacked }) {
401401
if (isPacked) {
402402
itemContent = (
403403
<del>
404-
{name + " "}
404+
{name + " "}
405405
</del>
406406
);
407407
}
@@ -464,7 +464,7 @@ export default function PackingList() {
464464
function Item({ name, isPacked }) {
465465
return (
466466
<li className="item">
467-
{name} {isPacked && ''}
467+
{name} {isPacked && ''}
468468
</li>
469469
);
470470
}
@@ -502,7 +502,7 @@ export default function PackingList() {
502502
function Item({ name, isPacked }) {
503503
return (
504504
<li className="item">
505-
{name} {isPacked ? '' : ''}
505+
{name} {isPacked ? '' : ''}
506506
</li>
507507
);
508508
}

src/content/learn/describing-the-ui.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ In this example, the JavaScript `&&` operator is used to conditionally render a
327327
function Item({ name, isPacked }) {
328328
return (
329329
<li className="item">
330-
{name} {isPacked && ''}
330+
{name} {isPacked && ''}
331331
</li>
332332
);
333333
}

src/content/learn/you-might-not-need-an-effect.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -408,9 +408,9 @@ function Game() {
408408
409409
There are two problems with this code.
410410
411-
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.
411+
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.
412412
413-
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.
413+
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.
414414
415415
In this case, it's better to calculate what you can during rendering, and adjust the state in the event handler:
416416

vercel.json

+5
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@
2424
"destination": "/learn/rendering-lists#keeping-list-items-in-order-with-key",
2525
"permanent": false
2626
},
27+
{
28+
"source": "/docs/lists-and-keys",
29+
"destination": "/learn/rendering-lists#keeping-list-items-in-order-with-key",
30+
"permanent": false
31+
},
2732
{
2833
"source": "/link/invalid-hook-call",
2934
"destination": "/warnings/invalid-hook-call-warning",

0 commit comments

Comments
 (0)