@@ -94,9 +94,7 @@ export type Dispatcher = {
9494 props : Object ,
9595 ) : ReactEventResponderListener < E , C > ,
9696 useDeferredValue < T > ( value : T , config : TimeoutConfig | void | null ) : T ,
97- useTransition (
98- config : SuspenseConfig | void | null ,
99- ) : [ ( ( ) => void ) => void , boolean ] ,
97+ useTransition ( ) : [ ( ( ) => void ) => void , boolean ] ,
10098} ;
10199
102100type Update < S , A > = {
@@ -1172,50 +1170,32 @@ function updateDeferredValue<T>(
11721170 return prevValue ;
11731171}
11741172
1175- function mountTransition(
1176- config: SuspenseConfig | void | null,
1177- ): [(() => void ) => void , boolean ] {
1173+ function startTransition(setPending, callback, config) {
1174+ setPending ( true ) ;
1175+ Scheduler . unstable_next ( ( ) => {
1176+ const previousConfig = ReactCurrentBatchConfig . suspense ;
1177+ ReactCurrentBatchConfig . suspense = config === undefined ? null : config ;
1178+ try {
1179+ setPending ( false ) ;
1180+ callback ( ) ;
1181+ } finally {
1182+ ReactCurrentBatchConfig . suspense = previousConfig ;
1183+ }
1184+ } ) ;
1185+ }
1186+
1187+ function mountTransition(): [(() => void ) => void , boolean ] {
11781188 const [ isPending , setPending ] = mountState ( false ) ;
1179- const startTransition = mountCallback (
1180- callback => {
1181- setPending ( true ) ;
1182- Scheduler . unstable_next ( ( ) => {
1183- const previousConfig = ReactCurrentBatchConfig . suspense ;
1184- ReactCurrentBatchConfig . suspense = config === undefined ? null : config ;
1185- try {
1186- setPending ( false ) ;
1187- callback ( ) ;
1188- } finally {
1189- ReactCurrentBatchConfig . suspense = previousConfig ;
1190- }
1191- } ) ;
1192- } ,
1193- [ config , isPending ] ,
1194- ) ;
1195- return [ startTransition , isPending ] ;
1189+ const hook = mountWorkInProgressHook ( ) ;
1190+ const start = ( hook . memoizedState = startTransition . bind ( null , setPending ) ) ;
1191+ return [ start , isPending ] ;
11961192}
11971193
1198- function updateTransition(
1199- config: SuspenseConfig | void | null,
1200- ): [(() => void ) => void , boolean ] {
1201- const [ isPending , setPending ] = updateState ( false ) ;
1202- const startTransition = updateCallback (
1203- callback => {
1204- setPending ( true ) ;
1205- Scheduler . unstable_next ( ( ) => {
1206- const previousConfig = ReactCurrentBatchConfig . suspense ;
1207- ReactCurrentBatchConfig . suspense = config === undefined ? null : config ;
1208- try {
1209- setPending ( false ) ;
1210- callback ( ) ;
1211- } finally {
1212- ReactCurrentBatchConfig . suspense = previousConfig ;
1213- }
1214- } ) ;
1215- } ,
1216- [ config , isPending ] ,
1217- ) ;
1218- return [ startTransition , isPending ] ;
1194+ function updateTransition(): [(() => void ) => void , boolean ] {
1195+ const [ isPending ] = updateState ( false ) ;
1196+ const hook = updateWorkInProgressHook ( ) ;
1197+ const start = hook . memoizedState ;
1198+ return [ start , isPending ] ;
12191199}
12201200
12211201function dispatchAction< S , A > (
@@ -1553,12 +1533,10 @@ if (__DEV__) {
15531533 mountHookTypesDev ( ) ;
15541534 return mountDeferredValue ( value , config ) ;
15551535 } ,
1556- useTransition(
1557- config: SuspenseConfig | void | null,
1558- ): [(() => void ) => void , boolean ] {
1536+ useTransition(): [(() => void ) => void , boolean ] {
15591537 currentHookNameInDev = 'useTransition' ;
15601538 mountHookTypesDev ( ) ;
1561- return mountTransition ( config ) ;
1539+ return mountTransition ( ) ;
15621540 } ,
15631541 } ;
15641542
@@ -1670,12 +1648,10 @@ if (__DEV__) {
16701648 updateHookTypesDev ( ) ;
16711649 return mountDeferredValue ( value , config ) ;
16721650 } ,
1673- useTransition(
1674- config: SuspenseConfig | void | null,
1675- ): [(() => void ) => void , boolean ] {
1651+ useTransition(): [(() => void ) => void , boolean ] {
16761652 currentHookNameInDev = 'useTransition' ;
16771653 updateHookTypesDev ( ) ;
1678- return mountTransition ( config ) ;
1654+ return mountTransition ( ) ;
16791655 } ,
16801656 } ;
16811657
@@ -1787,12 +1763,10 @@ if (__DEV__) {
17871763 updateHookTypesDev ( ) ;
17881764 return updateDeferredValue ( value , config ) ;
17891765 } ,
1790- useTransition(
1791- config: SuspenseConfig | void | null,
1792- ): [(() => void ) => void , boolean ] {
1766+ useTransition(): [(() => void ) => void , boolean ] {
17931767 currentHookNameInDev = 'useTransition' ;
17941768 updateHookTypesDev ( ) ;
1795- return updateTransition ( config ) ;
1769+ return updateTransition ( ) ;
17961770 } ,
17971771 } ;
17981772
@@ -1917,13 +1891,11 @@ if (__DEV__) {
19171891 mountHookTypesDev ( ) ;
19181892 return mountDeferredValue ( value , config ) ;
19191893 } ,
1920- useTransition(
1921- config: SuspenseConfig | void | null,
1922- ): [(() => void ) => void , boolean ] {
1894+ useTransition(): [(() => void ) => void , boolean ] {
19231895 currentHookNameInDev = 'useTransition' ;
19241896 warnInvalidHookAccess ( ) ;
19251897 mountHookTypesDev ( ) ;
1926- return mountTransition ( config ) ;
1898+ return mountTransition ( ) ;
19271899 } ,
19281900 } ;
19291901
@@ -2048,13 +2020,11 @@ if (__DEV__) {
20482020 updateHookTypesDev ( ) ;
20492021 return updateDeferredValue ( value , config ) ;
20502022 } ,
2051- useTransition(
2052- config: SuspenseConfig | void | null,
2053- ): [(() => void ) => void , boolean ] {
2023+ useTransition(): [(() => void ) => void , boolean ] {
20542024 currentHookNameInDev = 'useTransition' ;
20552025 warnInvalidHookAccess ( ) ;
20562026 updateHookTypesDev ( ) ;
2057- return updateTransition ( config ) ;
2027+ return updateTransition ( ) ;
20582028 } ,
20592029 } ;
20602030}
0 commit comments