Commit 655915c
committed
Implement experimental_useOptimisticState (#26740)
This adds an experimental hook tentatively called useOptimisticState.
(The actual name needs some bikeshedding.)
The headline feature is that you can use it to implement optimistic
updates. If you set some optimistic state during a transition/action,
the state will be automatically reverted once the transition completes.
Another feature is that the optimistic updates will be continually
rebased on top of the latest state.
It's easiest to explain with examples; we'll publish documentation as
the API gets closer to stabilizing. See tests for now.
Technically the use cases for this hook are broader than just optimistic
updates; you could use it implement any sort of "pending" state, such as
the ones exposed by useTransition and useFormStatus. But we expect
people will most often reach for this hook to implement the optimistic
update pattern; simpler cases are covered by those other hooks.
DiffTrain build for [491aec5](491aec5)1 parent 0f3ca2b commit 655915c
File tree
30 files changed
+5027
-2485
lines changed- compiled/facebook-www
30 files changed
+5027
-2485
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
30 | | - | |
| 30 | + | |
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| |||
2026 | 2026 | | |
2027 | 2027 | | |
2028 | 2028 | | |
| 2029 | + | |
| 2030 | + | |
| 2031 | + | |
| 2032 | + | |
| 2033 | + | |
2029 | 2034 | | |
2030 | 2035 | | |
2031 | 2036 | | |
| |||
4175 | 4180 | | |
4176 | 4181 | | |
4177 | 4182 | | |
| 4183 | + | |
4178 | 4184 | | |
4179 | 4185 | | |
4180 | 4186 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
30 | | - | |
| 30 | + | |
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| |||
2026 | 2026 | | |
2027 | 2027 | | |
2028 | 2028 | | |
| 2029 | + | |
| 2030 | + | |
| 2031 | + | |
| 2032 | + | |
| 2033 | + | |
2029 | 2034 | | |
2030 | 2035 | | |
2031 | 2036 | | |
| |||
4139 | 4144 | | |
4140 | 4145 | | |
4141 | 4146 | | |
| 4147 | + | |
4142 | 4148 | | |
4143 | 4149 | | |
4144 | 4150 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
536 | 536 | | |
537 | 537 | | |
538 | 538 | | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
539 | 545 | | |
540 | 546 | | |
541 | 547 | | |
| |||
646 | 652 | | |
647 | 653 | | |
648 | 654 | | |
649 | | - | |
| 655 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
529 | 529 | | |
530 | 530 | | |
531 | 531 | | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
532 | 538 | | |
533 | 539 | | |
534 | 540 | | |
| |||
638 | 644 | | |
639 | 645 | | |
640 | 646 | | |
641 | | - | |
| 647 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
547 | 547 | | |
548 | 548 | | |
549 | 549 | | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
550 | 556 | | |
551 | 557 | | |
552 | 558 | | |
| |||
657 | 663 | | |
658 | 664 | | |
659 | 665 | | |
660 | | - | |
| 666 | + | |
661 | 667 | | |
662 | 668 | | |
663 | 669 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
540 | 540 | | |
541 | 541 | | |
542 | 542 | | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
543 | 549 | | |
544 | 550 | | |
545 | 551 | | |
| |||
649 | 655 | | |
650 | 656 | | |
651 | 657 | | |
652 | | - | |
| 658 | + | |
653 | 659 | | |
654 | 660 | | |
655 | 661 | | |
| |||
0 commit comments