@@ -71,20 +71,10 @@ function HistoryNavigator({
71
71
[ navigation , state . index , state . key ] ,
72
72
) ;
73
73
74
- React . useEffect ( ( ) => {
75
- if ( history . index > state . index ) {
76
- history . go ( state . index - history . index ) ;
77
- } else if ( history . index < state . index ) {
78
- const route = state . routes [ state . index ] ;
79
- if ( route ) {
80
- // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
81
- // @ts -ignore
82
- history . push ( route . params ? `${ route . name } ?${ stringify ( route . params ) } ` : route . name ) ;
83
- }
84
- }
85
- const subscribes : ( ( ) => void ) [ ] = [ ] ;
86
- subscribes . push (
74
+ React . useEffect (
75
+ ( ) =>
87
76
history . listen ( ( location : Location < any > , action : Action ) : void => {
77
+ const state = navigation . dangerouslyGetState ( ) ;
88
78
if ( state . routeNames . includes ( location . pathname ) ) {
89
79
switch ( action ) {
90
80
case 'POP' :
@@ -105,17 +95,21 @@ function HistoryNavigator({
105
95
}
106
96
}
107
97
} ) ,
108
- ) ;
109
- return ( ) => {
110
- for ( const fn of subscribes ) {
111
- if ( typeof fn === 'function' ) {
112
- try {
113
- fn ( ) ;
114
- } catch ( ignored ) { }
115
- }
98
+ [ navigation , history ] ,
99
+ ) ;
100
+
101
+ React . useEffect ( ( ) => {
102
+ if ( history . index > state . index ) {
103
+ history . go ( state . index - history . index ) ;
104
+ } else if ( history . index < state . index ) {
105
+ const route = state . routes [ state . index ] ;
106
+ if ( route ) {
107
+ // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
108
+ // @ts -ignore
109
+ history . push ( route . params ? `${ route . name } ?${ stringify ( route . params ) } ` : route . name ) ;
116
110
}
117
- } ;
118
- } , [ navigation , history , state ] ) ;
111
+ }
112
+ } , [ state . index , history ] ) ;
119
113
120
114
return < StackView { ...rest } descriptors = { descriptors } state = { state } navigation = { navigation } /> ;
121
115
}
0 commit comments