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
@@ -457,7 +457,7 @@ Here, `liked => !liked` always toggles the latest state. If the base `isLiked` c
457
457
458
458
`useOptimistic` supports two patterns for calculating state based on current state:
459
459
460
-
**Updater functions** work just like [useState updaters](/reference/react/useState#updating-state-based-on-the-previous-state). Pass a function to the setter:
460
+
**Updater functions** work like [useState updaters](/reference/react/useState#updating-state-based-on-the-previous-state). Pass a function to the setter:
**Use updaters** for simple calculations where the setter call naturally describes the update. This is similar to using `setState(prev=>...)` with `useState`.
476
+
**Use updaters** for calculations where the setter call naturally describes the update. This is similar to using `setState(prev=>...)` with `useState`.
477
477
478
478
**Use reducers** when you need to pass data to the update (like which item to add) or when handling multiple types of updates with a single hook.
An optimistic state update occurred outside a transition or Action. To fix, move the update to an Action, or wrap with `startTransition`.
945
+
An optimistic state update occurred outside a Transition or Action. To fix, move the update to an Action, or wrap with `startTransition`.
936
946
937
947
</ConsoleLogLine>
938
948
@@ -941,7 +951,7 @@ An optimistic state update occurred outside a transition or Action. To fix, move
941
951
The optimistic setter function must be called inside a Transition:
942
952
943
953
```js
944
-
//❌ Incorrect: outside a Transition
954
+
//🚩 Incorrect: outside a Transition
945
955
functionhandleClick() {
946
956
setOptimistic(newValue); // Warning!
947
957
// ...
@@ -981,7 +991,7 @@ Cannot update optimistic state while rendering.
981
991
This error occurs when you call the optimistic setter during the render phase of a component. You can only call it from event handlers, effects, or other callbacks:
0 commit comments