@@ -17,36 +17,38 @@ export function useUnwrapState(state: ReducerState): AppRouterState {
17
17
18
18
return state
19
19
}
20
-
21
20
export function useReducer (
22
21
actionQueue : AppRouterActionQueue
23
22
) : [ ReducerState , Dispatch < ReducerActions > ] {
24
23
const [ state , setState ] = React . useState < ReducerState > ( actionQueue . state )
25
- const actionDispatch = ( action : ReducerActions ) => {
26
- actionQueue . dispatch ( action , setState )
27
- }
28
24
29
- let syncDevRenderIndicator
25
+ const syncDevRenderIndicatorInDevelopment =
26
+ useSyncDevRenderIndicatorInDevelopment ( )
27
+
28
+ const dispatch = useCallback (
29
+ ( action : ReducerActions ) => {
30
+ syncDevRenderIndicatorInDevelopment ( ( ) =>
31
+ actionQueue . dispatch ( action , setState )
32
+ )
33
+ } ,
34
+ [ actionQueue , syncDevRenderIndicatorInDevelopment ]
35
+ )
36
+
37
+ return [ state , dispatch ]
38
+ }
39
+
40
+ const PASS_THROUGH = ( fn : ( ) => void ) => fn ( )
41
+
42
+ const useSyncDevRenderIndicatorInDevelopment = ( ) => {
30
43
if ( process . env . NODE_ENV !== 'production' ) {
31
44
const useSyncDevRenderIndicator =
32
45
require ( './react-dev-overlay/utils/dev-indicator/use-sync-dev-render-indicator' )
33
46
. useSyncDevRenderIndicator as typeof import ( './react-dev-overlay/utils/dev-indicator/use-sync-dev-render-indicator' ) . useSyncDevRenderIndicator
47
+
34
48
// eslint-disable-next-line react-hooks/rules-of-hooks
35
- syncDevRenderIndicator = useSyncDevRenderIndicator ( )
49
+ const syncDevRenderIndicator = useSyncDevRenderIndicator ( )
50
+ return syncDevRenderIndicator
51
+ } else {
52
+ return PASS_THROUGH
36
53
}
37
-
38
- const dispatchCallback =
39
- process . env . NODE_ENV !== 'production'
40
- ? ( action : ReducerActions ) => {
41
- syncDevRenderIndicator ! ( ( ) => actionDispatch ( action ) )
42
- }
43
- : actionDispatch
44
-
45
- const dispatch = useCallback ( dispatchCallback , [
46
- actionQueue ,
47
- dispatchCallback ,
48
- syncDevRenderIndicator ,
49
- ] )
50
-
51
- return [ state , dispatch ]
52
54
}
0 commit comments