React-Navigation: How to pass data between tabs in TabNavigation? code example
Example 1: reset navigation to specific tab react-navigation
navigation.reset({
index: 1,
routes: [
{
name: 'Screen1',
state: {
routes: [{ name: 'Tab2' }],
},
},
{
name: 'Screen1',
state: {
routes: [
{
name: 'Tab2',
state: {
routes: [{ name: 'Screen5' }, { name: 'Screen4' }]
},
},
],
},
},
],
})
Example 2: react native tab navigation
import * as React from 'react';
import { Text, View } from 'react-native';
import { NavigationContainer } from '@react-navigation/native';
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
function HomeScreen() {
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Text>Home!</Text>
</View>
);
}
function SettingsScreen() {
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Text>Settings!</Text>
</View>
);
}
const Tab = createBottomTabNavigator();
export default function App() {
return (
<NavigationContainer>
<Tab.Navigator>
<Tab.Screen name="Home" component={HomeScreen} />
<Tab.Screen name="Settings" component={SettingsScreen} />
</Tab.Navigator>
</NavigationContainer>
);
}