Challenge - 5 Problems
Parameter Passing Pro
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediatePassing parameters with React Navigation
What will be displayed on the second screen when navigating with this code snippet?
React Native
navigation.navigate('Details', { itemId: 42, message: 'Hello' }); // On Details screen: const { itemId, message } = route.params; return <Text>{`ID: ${itemId}, Msg: ${message}`}</Text>;
Attempts:
2 left
💡 Hint
Check how parameters are passed and accessed via route.params.
✗ Incorrect
The parameters passed in navigation.navigate are accessible in the target screen via route.params. Here, itemId is 42 and message is 'Hello', so the text shows both correctly.
📝 Syntax
intermediateCorrect way to access route parameters
Which option correctly accesses the parameter 'userName' passed to a screen?
React Native
navigation.navigate('Profile', { userName: 'Alice' });
Attempts:
2 left
💡 Hint
Parameters are accessed from route.params, not navigation or props.navigation.
✗ Incorrect
In React Navigation, the route object contains params. So route.params.userName is the correct way to get the parameter.
❓ lifecycle
advancedParameter update on screen focus
If a screen receives parameters and you want to update UI when parameters change after navigation, which React hook is best to use?
Attempts:
2 left
💡 Hint
Think about reacting to changes in parameters.
✗ Incorrect
useEffect with route.params as dependency runs when parameters change, allowing UI update. componentDidMount runs only once, so it won't detect changes.
advanced
Passing parameters back to previous screen
How can you pass data back to the previous screen after navigating back?
Attempts:
2 left
💡 Hint
Passing data back usually involves callbacks or events, not just params.
✗ Incorrect
You can pass a callback function as a parameter when navigating to a screen. When going back, call that function with data to send it back.
🔧 Debug
expertWhy does parameter not update on screen?
Given this code, why does the displayed parameter not update when navigating back with new params?
Screen A:
navigation.navigate('ScreenB', { count: 1 });
Screen B:
const { count } = route.params;
return {count} ;
Later, Screen A navigates again:
navigation.navigate('ScreenB', { count: 2 });
Attempts:
2 left
💡 Hint
Think about screen mounting and parameter updates in navigation stacks.
✗ Incorrect
If Screen B is already mounted, navigating to it again does not remount it, so route.params do not update automatically. You need to listen to focus events or use hooks to update.
