File tree 2 files changed +5
-3
lines changed
2 files changed +5
-3
lines changed Original file line number Diff line number Diff line change 1
- import React , { useEffect , useState } from "react" ;
1
+ import React , { useState } from "react" ;
2
2
import "./App.css" ;
3
3
import { IonApp , IonPage , IonRouterOutlet } from "@ionic/react" ;
4
4
import { IonReactRouter } from "@ionic/react-router" ;
Original file line number Diff line number Diff line change 1
1
import { useIonRouter } from "@ionic/react" ;
2
- import React , { useContext , useEffect } from "react" ;
2
+ import React , { useEffect } from "react" ;
3
3
4
4
type NavigateOnStateChangeProps = { route ?: string , onNavigate ?: ( ) => void }
5
5
6
6
export const NavigateOnStateChange : React . FC < NavigateOnStateChangeProps > = ( { route, onNavigate} ) => {
7
7
const ionRouter = useIonRouter ( ) ;
8
8
console . log ( "NavigateOnStateChange" , ionRouter ) ;
9
9
useEffect ( ( ) => {
10
- if ( route ) {
10
+ if ( route && ionRouter ) {
11
11
console . log ( "Route changed " , route ) ;
12
12
setTimeout ( ( ) => {
13
13
ionRouter . push ( route ) ;
@@ -16,6 +16,8 @@ export const NavigateOnStateChange: React.FC<NavigateOnStateChangeProps> = ({rou
16
16
onNavigate ( ) ;
17
17
}
18
18
}
19
+ /* This useEffect should ONLY run when route changes */
20
+ // eslint-disable-next-line react-hooks/exhaustive-deps
19
21
} , [ route ] ) ;
20
22
return < > </ >
21
23
}
You can’t perform that action at this time.
0 commit comments