Challenge - 5 Problems
Props Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate2: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" />Attempts:
2 left
💡 Hint
Props are used to pass data from parent to child components.
✗ Incorrect
The component uses props.name to show the passed value 'Alice'. So it displays 'Hello, Alice!'.
📝 Syntax
intermediate2: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>;
}Attempts:
2 left
💡 Hint
Use curly braces for numbers and quotes for strings in JSX props.
✗ Incorrect
Option A correctly passes a string prop with quotes and a number prop with curly braces.
❓ lifecycle
advanced2: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?Attempts:
2 left
💡 Hint
React updates components when props change to keep UI in sync.
✗ Incorrect
React re-renders child components when their props change to update the UI accordingly.
🔧 Debug
advanced2: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!" />Attempts:
2 left
💡 Hint
Inside the component, you must access props with 'props.' prefix.
✗ Incorrect
The code uses 'message' directly, which is undefined. It should use 'props.message' to access the prop.
🧠 Conceptual
expert2: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?
Attempts:
2 left
💡 Hint
Think about how data flows in React apps and why explicit data passing is helpful.
✗ Incorrect
Props let components receive data clearly from parents, making them reusable and easier to understand.