Commit c4eb235
committed
fix(learn): Improve error handling in state management examples
This commit fixes a UX bug in the "City quiz" examples where a submission
error would persist on screen even after the user started typing a new answer.
The new behavior clears the error message as soon as the user takes a
corrective action (typing) or initiates a new submission.
The implementation uses a declarative approach by deriving the error's
visibility on each render. This design was chosen for two key reasons:
1. It avoids manual state clearing in event handlers, which is a more
robust and less error-prone pattern.
2. It respects the tutorial's pedagogical flow by using only concepts
introduced up to that point (e.g., `useState`, derived state) without
requiring more advanced hooks.1 parent 5c632dc commit c4eb235
File tree
2 files changed
+7
-3
lines changed- src/content/learn
2 files changed
+7
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| 38 | + | |
38 | 39 | | |
39 | 40 | | |
40 | 41 | | |
| |||
49 | 50 | | |
50 | 51 | | |
51 | 52 | | |
| 53 | + | |
52 | 54 | | |
53 | 55 | | |
54 | 56 | | |
| |||
75 | 77 | | |
76 | 78 | | |
77 | 79 | | |
78 | | - | |
| 80 | + | |
79 | 81 | | |
80 | 82 | | |
81 | 83 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
| 60 | + | |
60 | 61 | | |
61 | 62 | | |
62 | 63 | | |
| |||
414 | 415 | | |
415 | 416 | | |
416 | 417 | | |
| 418 | + | |
417 | 419 | | |
418 | 420 | | |
419 | 421 | | |
| |||
427 | 429 | | |
428 | 430 | | |
429 | 431 | | |
430 | | - | |
| 432 | + | |
431 | 433 | | |
432 | 434 | | |
433 | 435 | | |
| |||
454 | 456 | | |
455 | 457 | | |
456 | 458 | | |
457 | | - | |
| 459 | + | |
458 | 460 | | |
459 | 461 | | |
460 | 462 | | |
| |||
0 commit comments