You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/reference/react/useTransition.md
+159Lines changed: 159 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -1948,3 +1948,162 @@ When clicking multiple times, it's possible for previous requests to finish afte
1948
1948
This is expected, because Actions within a Transition do not guarantee execution order. For common use cases, React provides higher-level abstractions like [`useActionState`](/reference/react/useActionState) and [`<form>` actions](/reference/react-dom/components/form) that handle ordering for you. For advanced use cases, you'll need to implement your own queuing and abort logic to handle this.
1949
1949
1950
1950
1951
+
Example of `useActionState` handling execution order:
1952
+
1953
+
<Sandpack>
1954
+
1955
+
```json package.json hidden
1956
+
{
1957
+
"dependencies": {
1958
+
"react":"beta",
1959
+
"react-dom":"beta"
1960
+
},
1961
+
"scripts": {
1962
+
"start":"react-scripts start",
1963
+
"build":"react-scripts build",
1964
+
"test":"react-scripts test --env=jsdom",
1965
+
"eject":"react-scripts eject"
1966
+
}
1967
+
}
1968
+
```
1969
+
1970
+
```js src/App.js
1971
+
import { useState, useActionState } from"react";
1972
+
import { updateQuantity } from"./api";
1973
+
importItemfrom"./Item";
1974
+
importTotalfrom"./Total";
1975
+
1976
+
exportdefaultfunctionApp({}) {
1977
+
// Store the actual quantity in separate state to show the mismatch.
0 commit comments