0
0
React Nativemobile~20 mins

Passing parameters between screens in React Native - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Parameter Passing Pro
Get all challenges correct to earn this badge!
Test your skills under time pressure!
ui_behavior
intermediate
2:00remaining
Passing 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>;
AID: 42, Msg: Hello
BID: 42, Msg: undefined
CID: undefined, Msg: undefined
DID: Hello, Msg: 42
Attempts:
2 left
💡 Hint
Check how parameters are passed and accessed via route.params.
📝 Syntax
intermediate
1:30remaining
Correct way to access route parameters
Which option correctly accesses the parameter 'userName' passed to a screen?
React Native
navigation.navigate('Profile', { userName: 'Alice' });
Aconst user = props.navigation.userName;
Bconst user = props.route.params.userName;
Cconst user = route.params.userName;
Dconst user = navigation.params.userName;
Attempts:
2 left
💡 Hint
Parameters are accessed from route.params, not navigation or props.navigation.
lifecycle
advanced
2:00remaining
Parameter 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?
AcomponentDidMount lifecycle method
BuseState without dependencies
CuseLayoutEffect without dependencies
DuseEffect with route.params as dependency
Attempts:
2 left
💡 Hint
Think about reacting to changes in parameters.
navigation
advanced
2:30remaining
Passing parameters back to previous screen
How can you pass data back to the previous screen after navigating back?
AUse navigation.navigate with params on the previous screen
BUse navigation.goBack() and a callback function passed as a param
CUse global variables to share data between screens
DUse route.params to send data back automatically
Attempts:
2 left
💡 Hint
Passing data back usually involves callbacks or events, not just params.
🔧 Debug
expert
3:00remaining
Why 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 });
AScreen B is already mounted, so params do not update automatically
Broute.params is immutable and cannot change after first render
Cnavigation.navigate does not accept parameters
DText component cannot display numbers
Attempts:
2 left
💡 Hint
Think about screen mounting and parameter updates in navigation stacks.