Skip to content

Commit 7968379

Browse files
Update choosing-the-state-structure.md
1 parent e9a7cb1 commit 7968379

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/content/learn/choosing-the-state-structure.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ function Message({ messageColor }) {
355355
356356
Here, a `color` state variable is initialized to the `messageColor` prop. The problem is that **if the parent component passes a different value of `messageColor` later (for example, `'red'` instead of `'blue'`), the `color` *state variable* would not be updated!** The state is only initialized during the first render.
357357
358-
This is why "mirroring" some prop in a state variable can lead to confusion. Instead, use the `messageColor` prop directly in your code. If you want to give it a shorter name, use a constant:
358+
This is why mirroring some prop in a state variable can lead to confusion. Instead, use the `messageColor` prop directly in your code. If you want to give it a shorter name, use a constant:
359359
360360
```js
361361
function Message({ messageColor }) {
@@ -364,7 +364,7 @@ function Message({ messageColor }) {
364364
365365
This way it won't get out of sync with the prop passed from the parent component.
366366
367-
"Mirroring" props into state only makes sense when you *want* to ignore all updates for a specific prop. By convention, start the prop name with `initial` or `default` to clarify that its new values are ignored:
367+
Mirroring props into state only makes sense when you *want* to ignore all updates for a specific prop. By convention, start the prop name with `initial` or `default` to clarify that its new values are ignored:
368368
369369
```js
370370
function Message({ initialColor }) {

0 commit comments

Comments
 (0)