0
0
Reactframework~20 mins

Passing props to components in React - 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!
component_behavior
intermediate
2:00remaining
What is the output of this React component?
Consider this React component that receives props and renders a greeting message. What will be displayed on the screen?
React
function Greeting({ name }) {
  return <h1>Hello, {name}!</h1>;
}

// Usage
<Greeting name="Alice" />
AError: name is not defined
BHello, name!
CHello, !
DHello, Alice!
Attempts:
2 left
💡 Hint
Look at how the prop 'name' is used inside the component.
state_output
intermediate
2:00remaining
What is the value of the prop inside the child component?
Given the parent component passing a prop to a child, what will the child component receive as the value of the prop count?
React
function Parent() {
  const count = 5;
  return <Child count={count} />;
}

function Child({ count }) {
  return <p>{count}</p>;
}
A5
Bundefined
C0
Dnull
Attempts:
2 left
💡 Hint
Check what value is passed from Parent to Child.
📝 Syntax
advanced
2:00remaining
Which option correctly passes multiple props to a component?
You want to pass two props, title and subtitle, to a component. Which option is syntactically correct in React?
A<Header title="Welcome" subtitle="Home" />
B<Header title="Welcome", subtitle="Home" />
C<Header title="Welcome"; subtitle="Home" />
D<Header title="Welcome" subtitle="Home"></Header>
Attempts:
2 left
💡 Hint
Props are passed like HTML attributes separated by spaces, not commas or semicolons.
🔧 Debug
advanced
2:00remaining
Why does this component fail to receive the prop?
Look at this code. Why does the Child component not display the passed prop message?
React
function Parent() {
  const message = "Hi!";
  return <Child msg={message} />;
}

function Child({ message }) {
  return <p>{message}</p>;
}
AThe prop name in Parent and Child do not match (msg vs message).
BThe Child component is missing a return statement.
CThe Parent component does not pass any props.
DThe message variable is not defined in Parent.
Attempts:
2 left
💡 Hint
Check the prop names used in Parent and Child components.
🧠 Conceptual
expert
2:00remaining
What happens if a required prop is not passed to a component?
Consider a React component that expects a prop but the parent does not pass it. What is the typical behavior?
React
function Display({ text }) {
  return <p>{text}</p>;
}

// Usage
<Display />
AThe component renders nothing and no error occurs.
BReact throws a runtime error and crashes the app.
CThe component renders <p>undefined</p> because the prop is missing.
DReact automatically assigns an empty string to missing props.
Attempts:
2 left
💡 Hint
Think about what happens when you use a variable that is undefined inside JSX.