@@ -25,16 +25,18 @@ type Message = {
25
25
// trying to manage one pending state, we get a scenario where the first
26
26
// one that comes back sets pending to false, yet there are still some pending.
27
27
28
+ // START --------------------> Resolve (sets pending false)
29
+ // START --------------------> Resolve
30
+ // START --------------------> Resolve
31
+
28
32
// Also, we are "closing over" and empty items array three times and when
29
33
// each response resolves, they all try to set their state on that empty array
30
34
// We'll use the setState(fn) approach to avoid closure
31
35
32
36
// Note that the pending status goes to false on the first resolve and yet
33
37
// not of the other items have resolved yet
34
38
35
- // START --------------------> Resolve (sets pending false)
36
- // START --------------------> Resolve
37
- // START --------------------> Resolve
39
+ // Add transitions to manage pending status...
38
40
39
41
export function App ( ) {
40
42
const messageRef = useRef < HTMLInputElement > ( null ! )
@@ -88,18 +90,12 @@ export function App() {
88
90
}
89
91
90
92
/**
91
- * Example 2: startTransition
93
+ * Example 1: Finished
92
94
*/
93
95
94
- // Managing the pending status with a transition fixes the pending issue we
95
- // were having before. Now the pending status stays pending until all async
96
- // transitions are finished. This is because we're not managing "pending"
97
- // ourselves but instead letting a tool that knows about our queue of async
98
- // transitions is managing it.
99
-
100
96
// START --------------------> Resolve
101
97
// START --------------------> Resolve
102
- // START --------------------> Resolve
98
+ // START --------------------> Resolve (sets pending false)
103
99
104
100
// export function App() {
105
101
// const messageRef = useRef<HTMLInputElement>(null!)
@@ -149,7 +145,7 @@ export function App() {
149
145
// }
150
146
151
147
/**
152
- * Example 3 : Form Actions
148
+ * Example 2 : Form Actions
153
149
*/
154
150
155
151
// 1. Use `action` instead of `onSubmit`
@@ -221,7 +217,7 @@ function Pending({ children }: { children: React.ReactNode }) {
221
217
}
222
218
223
219
/**
224
- * Example 4 : useActionState for single-submission forms
220
+ * Example 3 : useActionState for single-submission forms
225
221
*/
226
222
227
223
// 1. Make sure everyone knows how useReducer works and "reducing state"
@@ -286,7 +282,7 @@ function Pending({ children }: { children: React.ReactNode }) {
286
282
// }
287
283
288
284
/**
289
- * Example 5 : When to NOT use useActionState: rapid-fire repeat submissions
285
+ * Example 4 : When to NOT use useActionState: rapid-fire repeat submissions
290
286
*/
291
287
292
288
// START --------------------> Resolve
@@ -354,7 +350,7 @@ function Pending({ children }: { children: React.ReactNode }) {
354
350
// }
355
351
356
352
/**
357
- * Example 6 : Optimistic Forms
353
+ * Example 5 : Optimistic Forms
358
354
*/
359
355
360
356
// export function App() {
0 commit comments