'React Navigation 6.x - How to trigger navigation in parent navigator, and how to trigger method in child component?
I have a React Native app with a nested navigator structure like so:
StackA
-- Tabs
-- StackB
- From
StackB, is there a cleaner way to trigger a navigation onStackAthannavigation.getParent().getParent().navigate(...)? (eg: From within theNewscomponent, navigateStackA -> Article) - From
StackAorTab, how could I trigger a method on a screen withinStackB? (eg: When pressing theHometab button, trigger a method inside theNewscomponent)
My code looks something like:
function App () {
return (
<NavigationContainer>
<Stack.Navigator> {/* StackA */}
<Stack.Screen name="home" component={Tabs} /> /* Tab */
<Stack.Screen name="article" component={Article} />
</Stack.Navigator>
</NavigationContainer>
)
}
function Tabs () {
return(
<Tab.Navigator>
<Tab.screen name="home" component={Home} />
<Tab.screen name="search" component={Search} />
</Tab.Navigator>
)
}
function Home () {
return(
<Stack.Navigator> /* StackB */
<Stack.screen name="news" component={News} />
<Stack.screen name="archive" component={Archive} />
</Stack.Navigator>
)
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
