0
0
React Nativemobile~20 mins

Props passing in React Native - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Props Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
ui_behavior
intermediate
2:00remaining
What will be displayed by this component?
Consider this React Native component that receives a prop called name. What text will it show on the screen?
React Native
function Greeting(props) {
  return <Text>Hello, {props.name}!</Text>;
}

// Usage:
<Greeting name="Alice" />
AError: props is undefined
BHello, props.name!
CHello, Alice!
DHello, !
Attempts:
2 left
💡 Hint
Props are used to pass data from parent to child components.
📝 Syntax
intermediate
2:00remaining
Which option correctly passes multiple props?
You want to pass two props, title and count, to a component. Which usage is correct?
React Native
function Info(props) {
  return <Text>{props.title}: {props.count}</Text>;
}
A<Info title="Messages" count={5} />
B<Info title="Messages" count=5 />
C<Info title={"Messages"} count="5" />
D<Info title=Messages count=5 />
Attempts:
2 left
💡 Hint
Use curly braces for numbers and quotes for strings in JSX props.
lifecycle
advanced
2:00remaining
What happens if a prop changes in a functional component?
If a parent component passes a prop color to a child functional component, what happens when color changes?
AThe child component re-renders with the new prop value.
BThe child component ignores the change and keeps old value.
CThe child component unmounts and remounts.
DThe app crashes with an error.
Attempts:
2 left
💡 Hint
React updates components when props change to keep UI in sync.
🔧 Debug
advanced
2:00remaining
Why does this component show 'undefined' for a prop?
This component tries to show props.message but displays 'undefined'. What is the likely cause?
React Native
function ShowMessage(props) {
  return <Text>{message}</Text>;
}

// Usage:
<ShowMessage message="Hi!" />
AThe component must use state to show props.
BThe prop 'message' was not passed from parent.
CReact Native Text component cannot display props.
DThe component uses 'message' instead of 'props.message'.
Attempts:
2 left
💡 Hint
Inside the component, you must access props with 'props.' prefix.
🧠 Conceptual
expert
2:00remaining
What is the main benefit of passing props in React Native?
Why do React Native components use props to receive data instead of using global variables?
AProps automatically update the database with new values.
BProps make components reusable and predictable by passing data explicitly.
CProps allow components to change global variables directly.
DProps prevent components from rendering multiple times.
Attempts:
2 left
💡 Hint
Think about how data flows in React apps and why explicit data passing is helpful.