You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/docs/reference-react-component.md
+8-8Lines changed: 8 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -428,18 +428,18 @@ Think of `setState()` as a *request* rather than an immediate command to update
428
428
The first argument is an `updater` function with the signature:
429
429
430
430
```javascript
431
-
(prevState, props) => stateChange
431
+
(state, props) => stateChange
432
432
```
433
433
434
-
`prevState` is a reference to the previous state. It should not be directly mutated. Instead, changes should be represented by building a new object based on the input from `prevState` and `props`. For instance, suppose we wanted to increment a value in state by `props.step`:
434
+
`state` is a reference to the component state at the time the change is being applied. It should not be directly mutated. Instead, changes should be represented by building a new object based on the input from `state` and `props`. For instance, suppose we wanted to increment a value in state by `props.step`:
435
435
436
436
```javascript
437
-
this.setState((prevState, props) => {
438
-
return {counter:prevState.counter+props.step};
437
+
this.setState((state, props) => {
438
+
return {counter:state.counter+props.step};
439
439
});
440
440
```
441
441
442
-
Both `prevState` and `props` received by the updater function are guaranteed to be up-to-date. The output of the updater is shallowly merged with `prevState`.
442
+
Both `state` and `props` received by the updater function are guaranteed to be up-to-date. The output of the updater is shallowly merged with `state`.
443
443
444
444
The second parameter to `setState()` is an optional callback function that will be executed once `setState` is completed and the component is re-rendered. Generally we recommend using `componentDidUpdate()` for such logic instead.
445
445
@@ -466,11 +466,11 @@ Object.assign(
466
466
)
467
467
```
468
468
469
-
Subsequent calls will override values from previous calls in the same cycle, so the quantity will only be incremented once. If the next state depends on the previous state, we recommend using the updater function form, instead:
469
+
Subsequent calls will override values from previous calls in the same cycle, so the quantity will only be incremented once. If the next state depends on the current state, we recommend using the updater function form, instead:
Copy file name to clipboardExpand all lines: content/docs/state-and-lifecycle.md
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -359,18 +359,18 @@ To fix it, use a second form of `setState()` that accepts a function rather than
359
359
360
360
```js
361
361
// Correct
362
-
this.setState((prevState, props) => ({
363
-
counter:prevState.counter+props.increment
362
+
this.setState((state, props) => ({
363
+
counter:state.counter+props.increment
364
364
}));
365
365
```
366
366
367
367
We used an [arrow function](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Functions/Arrow_functions) above, but it also works with regular functions:
0 commit comments