Add note about skipped updates with noop setState

Fixes #2599.
This commit is contained in:
Sophie Alpert
2020-01-01 08:40:36 -08:00
committed by GitHub
parent f2920cc67b
commit 1e4023ed7d

View File

@@ -69,6 +69,8 @@ function Counter({initialCount}) {
The "+" and "-" buttons use the functional form, because the updated value is based on the previous value. But the "Reset" button uses the normal form, because it always sets the count back to the initial value.
If your update function returns the exact same value, the subsequent rerender will be skipped completely.
> Note
>
> Unlike the `setState` method found in class components, `useState` does not automatically merge update objects. You can replicate this behavior by combining the function updater form with object spread syntax: