Browse Source

Add note about skipped updates with noop setState

Fixes #2599.
main
Sophie Alpert 5 years ago
committed by GitHub
parent
commit
1e4023ed7d
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      content/docs/hooks-reference.md

2
content/docs/hooks-reference.md

@ -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:

Loading…
Cancel
Save