Skip to content

Commit ff17a86

Browse files
fix: correct typos and improve clarity in useOptimistic.md (#8283)
1 parent 38b52cf commit ff17a86

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/content/reference/react/useOptimistic.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,15 @@ This state is called the "optimistic" because it is used to immediately present
110110
111111
4. **(Optional) wait for Suspense**: If `newValue` suspends, React continues showing `'b'`.
112112
113-
5. **Single render commit**: Finally, the `newValue` is commits for `value` and `optimistic`.
113+
5. **Single render commit**: Finally, the `newValue` commits for `value` and `optimistic`.
114114
115115
There's no extra render to "clear" the optimistic state. The optimistic and real state converge in the same render when the Transition completes.
116116
117117
<Note>
118118
119119
#### Optimistic state is temporary {/*optimistic-state-is-temporary*/}
120120
121-
Optimistic state is only renders while an Action is in progress, otherwise `value` is rendered.
121+
Optimistic state only renders while an Action is in progress, otherwise `value` is rendered.
122122
123123
If `saveChanges` returned `'c'`, then both `value` and `optimistic` will be `'c'`, not `'b'`.
124124
@@ -403,7 +403,7 @@ export default function App() {
403403
}
404404

405405
if (optimisticIsLiked !== isLiked) {
406-
console.log('✅ rendering optmistic state: ' + optimisticIsLiked);
406+
console.log('✅ rendering optimistic state: ' + optimisticIsLiked);
407407
} else {
408408
console.log('✅ rendering real value: ' + optimisticIsLiked);
409409
}
@@ -1061,7 +1061,7 @@ If the values are not equal, there's a Transition in progress.
10611061
10621062
2. **Add a `useTransition`**
10631063
1064-
```
1064+
```js
10651065
const [isPending, startTransition] = useTransition();
10661066
const [optimistic, setOptimistic] = useOptimistic(value);
10671067

@@ -1071,13 +1071,15 @@ startTransition(() => {
10711071
})
10721072
```
10731073
1074-
Since `useTransition` uses `useOptimsitic` for `isPending` under the hood, this is equivalent to option 1.
1074+
Since `useTransition` uses `useOptimistic` for `isPending` under the hood, this is equivalent to option 1.
10751075
1076-
3**Add a `pending` flag in your reducer**
1076+
3. **Add a `pending` flag in your reducer**
10771077
10781078
```js
10791079
const [optimistic, addOptimistic] = useOptimistic(
10801080
items,
10811081
(state, newItem) => [...state, { ...newItem, isPending: true }]
10821082
);
10831083
```
1084+
1085+
Since each optimistic item has its own flag, you can show loading state for individual items.

0 commit comments

Comments
 (0)