Challenge - 5 Problems
Props Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate2:00remaining
Understanding Props in React Components
In React, what are props used for in functional components?
Attempts:
2 left
💡 Hint
Think about how components share information in React.
✗ Incorrect
Props are short for properties. They let a parent component send data to a child component. This helps components stay reusable and organized.
❓ component_behavior
intermediate2:00remaining
Props Usage in a Functional Component
What will be the output of this React component when rendered?
function Greeting(props) {
return Hello, {props.name}!
;
}
// Rendered as:
Attempts:
2 left
💡 Hint
Look at how the prop 'name' is accessed inside the component.
✗ Incorrect
The component receives a prop called name with value "Alice". It uses props.name to display it inside the <h1> tag.
📝 Syntax
advanced2:00remaining
Correct Syntax for Destructuring Props
Which option shows the correct way to use destructuring to access props in a React functional component?
React
function Welcome(____) { return <p>Welcome, {name}!</p>; }
Attempts:
2 left
💡 Hint
Destructuring props means extracting values inside the parentheses.
✗ Incorrect
Destructuring props means writing { name } inside the function parameters to directly access the name prop.
❓ state_output
advanced2:00remaining
Props vs State Behavior
Given this React component, what will be the output after clicking the button?
function Counter({ initial }) {
const [count, setCount] = React.useState(initial);
return (
<>
Count: {count}
>
);
}
// Rendered as:
Attempts:
2 left
💡 Hint
Look at how state is initialized and updated on button click.
✗ Incorrect
The state count starts at the initial prop value 5. Clicking the button increases count by 1 each time.
🔧 Debug
expert3:00remaining
Why Does This Prop Not Update?
Consider this React component:
Why does the console.log not show updated messages when 'text' changes?
function Display({ message }) {
React.useEffect(() => {
console.log('Message:', message);
}, []);
return {message}
;
}
// Parent renders: and updates 'text' over time
Why does the console.log not show updated messages when 'text' changes?
Attempts:
2 left
💡 Hint
Think about how useEffect dependencies control when the effect runs.
✗ Incorrect
The empty dependency array [] means the effect runs only once after the first render. It does not run again when props change.