Lesson 10 of 10
Practice & Quiz - React Navigation v6
Test your knowledge of Stack/Tab/Drawer navigators, type-safe params, auth flow pattern, and useFocusEffect with a practical exercise and 5 quiz questions.
Practical Exercise - Type-Safe Tab + Stack Navigation
import React from 'react';
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import { NavigationContainer } from '@react-navigation/native';
import { Text, View, Pressable } from 'react-native';
import type { NativeStackScreenProps } from '@react-navigation/native-stack';
import type { BottomTabScreenProps } from '@react-navigation/bottom-tabs';
// ─── Type-safe route params ────────────────────────────────────
type HomeStackParams = {
ProductList: undefined;
ProductDetail: { productId: string; productName: string };
};
type RootTabParams = {
Home: undefined;
Profile: undefined;
};
// ─── Screens ──────────────────────────────────────────────────
type ProductListProps = NativeStackScreenProps<HomeStackParams, 'ProductList'>;
function ProductListScreen({ navigation }: ProductListProps) {
return (
<View style={{ flex: 1, padding: 16 }}>
<Text style={{ fontSize: 20, fontWeight: '700' }}>Products</Text>
<Pressable
style={{ marginTop: 16, padding: 12, backgroundColor: '#229c6b', borderRadius: 8 }}
onPress={() => navigation.navigate('ProductDetail', {
productId: '42',
productName: 'Wireless Keyboard',
})}
>
<Text style={{ color: '#fff', fontWeight: '600' }}>View Keyboard</Text>
</Pressable>
</View>
);
}
type ProductDetailProps = NativeStackScreenProps<HomeStackParams, 'ProductDetail'>;
function ProductDetailScreen({ route, navigation }: ProductDetailProps) {
// params are fully typed - TypeScript knows productId and productName exist
const { productId, productName } = route.params;
return (
<View style={{ flex: 1, padding: 16 }}>
<Text style={{ fontSize: 20, fontWeight: '700' }}>{productName}</Text>
<Text style={{ color: '#666', marginTop: 8 }}>ID: {productId}</Text>
<Pressable onPress={() => navigation.goBack()}>
<Text style={{ color: '#229c6b', marginTop: 16 }}>← Back</Text>
</Pressable>
</View>
);
}
// ─── Stack inside Tab ─────────────────────────────────────────
const HomeStack = createNativeStackNavigator<HomeStackParams>();
function HomeStackNavigator() {
return (
<HomeStack.Navigator screenOptions={{ headerStyle: { backgroundColor: '#229c6b' }, headerTintColor: '#fff' }}>
<HomeStack.Screen name="ProductList" component={ProductListScreen} options={{ title: 'Products' }} />
<HomeStack.Screen name="ProductDetail" component={ProductDetailScreen} options={({ route }) => ({ title: route.params.productName })} />
</HomeStack.Navigator>
);
}
// ─── Root Tab Navigator ───────────────────────────────────────
const Tab = createBottomTabNavigator<RootTabParams>();
export default function App() {
return (
<NavigationContainer>
<Tab.Navigator>
<Tab.Screen name="Home" component={HomeStackNavigator} options={{ headerShown: false }} />
<Tab.Screen name="Profile" component={() => <View style={{ flex: 1 }}><Text>Profile</Text></View>} />
</Tab.Navigator>
</NavigationContainer>
);
}Module Quiz
Why use `createNativeStackNavigator` over `createStackNavigator` in React Navigation?
Tip
Tip
Practice Practice Quiz React Navigation v6 in small, isolated examples before integrating into larger projects. Breaking concepts into small experiments builds genuine understanding faster than reading alone.
Module 4 Knowledge Check: React Navigation stacks, tabs, and deep linking
Practice Task
Note
Practice Task - (1) Write a working example of Practice Quiz React Navigation v6 from scratch without looking at notes. (2) Modify it to handle an edge case (empty input, null value, or error state). (3) Share your solution in the Priygop community for feedback.
Common Mistake
Warning
A common mistake with Practice Quiz React Navigation v6 is skipping edge case testing - empty inputs, null values, and unexpected data types. Always validate boundary conditions to write robust, production-ready react native code.
Finished this lesson?