Challenge - 5 Problems
Stack Navigator Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate2:00remaining
What happens when you call navigation.navigate('Profile')?
Given a React Native app using React Navigation's Stack Navigator with two screens: Home and Profile, what is the result of calling
navigation.navigate('Profile') from the Home screen?React Native
import { createNativeStackNavigator } from '@react-navigation/native-stack'; import { NavigationContainer } from '@react-navigation/native'; const Stack = createNativeStackNavigator(); function HomeScreen({ navigation }) { return null; // Imagine a button calls navigation.navigate('Profile') } function ProfileScreen() { return null; } export default function App() { return ( <NavigationContainer> <Stack.Navigator> <Stack.Screen name="Home" component={HomeScreen} /> <Stack.Screen name="Profile" component={ProfileScreen} /> </Stack.Navigator> </NavigationContainer> ); }
Attempts:
2 left
💡 Hint
Think about how stack navigation works when you navigate to a new screen.
✗ Incorrect
Calling navigation.navigate('Profile') pushes the Profile screen on top of the current stack. The Home screen remains below it, so the user can go back.
❓ lifecycle
intermediate2:00remaining
What happens to the Home screen component when navigating to Profile?
In a Stack Navigator, when you navigate from Home to Profile, what happens to the Home screen component's state and lifecycle?
Attempts:
2 left
💡 Hint
Think about how stack navigation keeps screens in memory.
✗ Incorrect
Stack Navigator keeps previous screens mounted in the stack to preserve their state and lifecycle until popped.
📝 Syntax
advanced2:00remaining
Which code correctly defines a Stack Navigator with two screens?
Choose the correct React Native code snippet that defines a Stack Navigator with Home and Profile screens.
Attempts:
2 left
💡 Hint
Remember the correct import and component names for native stack navigator.
✗ Incorrect
Option C correctly uses createNativeStackNavigator and wraps screens inside with components.
advanced
2:00remaining
What is the effect of navigation.pop() in a Stack Navigator?
In a Stack Navigator, what happens when you call
navigation.pop() from the Profile screen?Attempts:
2 left
💡 Hint
Think about how pop works in a stack data structure.
✗ Incorrect
navigation.pop() removes the current top screen from the stack, revealing the previous screen underneath.
🔧 Debug
expert3:00remaining
Why does navigation.navigate('Profile') not work as expected?
You have a Stack Navigator with screens Home and Profile. From Home, calling
navigation.navigate('Profile') does not navigate to Profile. What is the most likely cause?React Native
const Stack = createNativeStackNavigator();
function App() {
return (
<NavigationContainer>
<Stack.Navigator>
<Stack.Screen name="Home" component={HomeScreen} />
{/* Profile screen is missing here */}
</Stack.Navigator>
</NavigationContainer>
);
}Attempts:
2 left
💡 Hint
Check if the screen name exists in the navigator.
✗ Incorrect
If the Profile screen is not registered in the Stack Navigator, navigation.navigate('Profile') cannot find it and does nothing.