Skip to content

Commit 9f48f6d

Browse files
committed
starting point
1 parent ee264ad commit 9f48f6d

File tree

1 file changed

+11
-15
lines changed
  • react/advanced-hooks/06-form-actions/lecture

1 file changed

+11
-15
lines changed

react/advanced-hooks/06-form-actions/lecture/App.tsx

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,18 @@ type Message = {
2525
// trying to manage one pending state, we get a scenario where the first
2626
// one that comes back sets pending to false, yet there are still some pending.
2727

28+
// START --------------------> Resolve (sets pending false)
29+
// START --------------------> Resolve
30+
// START --------------------> Resolve
31+
2832
// Also, we are "closing over" and empty items array three times and when
2933
// each response resolves, they all try to set their state on that empty array
3034
// We'll use the setState(fn) approach to avoid closure
3135

3236
// Note that the pending status goes to false on the first resolve and yet
3337
// not of the other items have resolved yet
3438

35-
// START --------------------> Resolve (sets pending false)
36-
// START --------------------> Resolve
37-
// START --------------------> Resolve
39+
// Add transitions to manage pending status...
3840

3941
export function App() {
4042
const messageRef = useRef<HTMLInputElement>(null!)
@@ -88,18 +90,12 @@ export function App() {
8890
}
8991

9092
/**
91-
* Example 2: startTransition
93+
* Example 1: Finished
9294
*/
9395

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-
10096
// START --------------------> Resolve
10197
// START --------------------> Resolve
102-
// START --------------------> Resolve
98+
// START --------------------> Resolve (sets pending false)
10399

104100
// export function App() {
105101
// const messageRef = useRef<HTMLInputElement>(null!)
@@ -149,7 +145,7 @@ export function App() {
149145
// }
150146

151147
/**
152-
* Example 3: Form Actions
148+
* Example 2: Form Actions
153149
*/
154150

155151
// 1. Use `action` instead of `onSubmit`
@@ -221,7 +217,7 @@ function Pending({ children }: { children: React.ReactNode }) {
221217
}
222218

223219
/**
224-
* Example 4: useActionState for single-submission forms
220+
* Example 3: useActionState for single-submission forms
225221
*/
226222

227223
// 1. Make sure everyone knows how useReducer works and "reducing state"
@@ -286,7 +282,7 @@ function Pending({ children }: { children: React.ReactNode }) {
286282
// }
287283

288284
/**
289-
* Example 5: When to NOT use useActionState: rapid-fire repeat submissions
285+
* Example 4: When to NOT use useActionState: rapid-fire repeat submissions
290286
*/
291287

292288
// START --------------------> Resolve
@@ -354,7 +350,7 @@ function Pending({ children }: { children: React.ReactNode }) {
354350
// }
355351

356352
/**
357-
* Example 6: Optimistic Forms
353+
* Example 5: Optimistic Forms
358354
*/
359355

360356
// export function App() {

0 commit comments

Comments
 (0)