Created
July 17, 2022 07:22
-
-
Save BAYiTUPAi/361a707e147afe3456ac9f5c500f8c53 to your computer and use it in GitHub Desktop.
Demonstrates ionic-react bug when passing props and using the /:tab(name) feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const App: React.FC = () => { | |
const [parentState, setParentState] = useState({value: 0}) | |
console.log("PARENT STATE: ", parentState) | |
useEffect(() => { | |
setTimeout(()=>{ | |
setParentState({value: parentState.value + 1}) | |
}, 5000) | |
}, [parentState]) | |
return ( | |
<IonApp> | |
<RoutesComponent parentState={parentState} setParentState={setParentState}/> | |
</IonApp> | |
) | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const RoutesComponent:React.FC<any> = ({parentState, setParentState}) => { | |
return ( | |
<IonReactRouter> | |
<IonTabs> | |
<IonRouterOutlet> | |
<Route exact path="/:tab(tab1)"> | |
<Tab1 childStateValue={parentState.value} /> | |
</Route> | |
<Route exact path="/tab2"> | |
<Tab2 /> | |
</Route> | |
<Route path="/tab3"> | |
<Tab3 /> | |
</Route> | |
<Route exact path="/"> | |
<Redirect to="/tab1" /> | |
</Route> | |
</IonRouterOutlet> | |
<IonTabBar slot="bottom"> | |
<IonTabButton tab="tab1" href="/tab1"> | |
<IonIcon icon={triangle} /> | |
<IonLabel>Tab 1</IonLabel> | |
</IonTabButton> | |
<IonTabButton tab="tab2" href="/tab2"> | |
<IonIcon icon={ellipse} /> | |
<IonLabel>Tab 2</IonLabel> | |
</IonTabButton> | |
<IonTabButton tab="tab3" href="/tab3"> | |
<IonIcon icon={square} /> | |
<IonLabel>Tab 3</IonLabel> | |
</IonTabButton> | |
</IonTabBar> | |
</IonTabs> | |
</IonReactRouter> | |
) | |
} | |
export default RoutesComponent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Tab1: React.FC<any> = ({childStateValue}) => { | |
console.log("CHILD STATE: ", childStateValue) | |
return ( | |
<IonPage> | |
<IonHeader> | |
<IonToolbar> | |
<IonTitle>Tab 1</IonTitle> | |
</IonToolbar> | |
</IonHeader> | |
<IonContent fullscreen> | |
<IonHeader collapse="condense"> | |
<IonToolbar> | |
<IonTitle size="large">Tab 1</IonTitle> | |
</IonToolbar> | |
</IonHeader> | |
<ExploreContainer name={`Tab 1 page - ${childStateValue}`}/> | |
</IonContent> | |
</IonPage> | |
); | |
}; | |
export default Tab1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment