Skip to content

Commit 2c0f46e

Browse files
authored
Merge pull request #65 from reactjs/sync-7d50c3ff
2 parents 36fc4fa + f310a02 commit 2c0f46e

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
5353
</Sandpack>
5454
55-
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}`.
55+
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}`.
5656
5757
You can write this as an [`if`/`else` statement](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/if...else) like so:
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 @@ If the `isPacked` prop is `true`, this code **returns a different JSX tree.** Wi
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 @@ In practice, returning `null` from a component isn't common because it might sur
159159
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:
160160

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

165165
is very similar to
@@ -172,7 +172,7 @@ Both of the conditional branches return `<li className="item">...</li>`:
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 @@ Instead of this:
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 @@ You can write this:
197197
```js
198198
return (
199199
<li className="item">
200-
{isPacked ? name + ' ' : name}
200+
{isPacked ? name + ' ' : name}
201201
</li>
202202
);
203203
```
204204

205-
You can read it as *"if `isPacked` is true, then (`?`) render `name + ' '`, otherwise (`:`) render `name`"*.
205+
You can read it as *"if `isPacked` is true, then (`?`) render `name + ' '`, otherwise (`:`) render `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 @@ Another common shortcut you'll encounter is the [JavaScript logical AND (`&&`) o
265265
```js
266266
return (
267267
<li className="item">
268-
{name} {isPacked && ''}
268+
{name} {isPacked && ''}
269269
</li>
270270
);
271271
```
@@ -280,7 +280,7 @@ Here it is in action:
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 @@ Use an `if` statement to reassign a JSX expression to `itemContent` if `isPacked
337337
338338
```js
339339
if (isPacked) {
340-
itemContent = name + " ";
340+
itemContent = name + " ";
341341
}
342342
```
343343
@@ -357,7 +357,7 @@ This style is the most verbose, but it's also the most flexible. Here it is in a
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 @@ Use the conditional operator (`cond ? a : b`) to render a ❌ if `isPacked` isn
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 @@ U ovom primeru, JavaScript `&&` operator se koristi da bi se uslovno prikazala k
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)