Bird
Raised Fist0
Reactframework~20 mins

Using props in JSX in React - Practice Problems & Coding Challenges

Choose your learning style10 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 will this React component render?
Consider this React component that uses props to display a greeting message. What will be the output when rendered with ?
React
function Greeting(props) {
  return <h1>Hello, {props.name}!</h1>;
}
A<h1>Hello, props.name!</h1>
B<h1>Hello, {name}!</h1>
C<h1>Hello, !</h1>
D<h1>Hello, Alice!</h1>
Attempts:
2 left
💡 Hint
Remember that props are accessed as properties of the props object inside JSX using curly braces.
❓ state_output
intermediate
2:00remaining
What is the output after clicking the button once?
This React component uses props and state. What will be the displayed text after clicking the button once?
React
import React, { useState } from 'react';

function Counter({ start }) {
  const [count, setCount] = useState(start);
  return (
    <div>
      <p>Count: {count}</p>
      <button onClick={() => setCount(count + 1)}>Increment</button>
    </div>
  );
}

// Rendered as <Counter start={5} />
ACount: 1
BCount: 6
CCount: 5
DCount: 0
Attempts:
2 left
💡 Hint
The initial state is set from the start prop. Clicking the button increases count by 1.
📝 Syntax
advanced
2:00remaining
Which option correctly passes multiple props to a component?
You want to pass two props, title and subtitle, to a React component called Header. Which JSX syntax is correct?
A<Header title="Welcome" subtitle="Home Page" />
B<Header title="Welcome", subtitle="Home Page" />
C<Header title={"Welcome"} subtitle={Home Page} />
D<Header title='Welcome' subtitle='Home Page'>
Attempts:
2 left
💡 Hint
Props in JSX are passed like HTML attributes without commas and with quotes or curly braces.
🔧 Debug
advanced
2:00remaining
Why does this component fail to display the prop value?
This React component tries to display a prop but shows nothing. What is the cause?
React
function ShowMessage(props) {
  return <p>Message: props.text</p>;
}

// Rendered as <ShowMessage text="Hello!" />
AThe prop name 'text' is incorrect; it should be 'message'.
BThe component is missing a return statement.
CThe prop is not inside curly braces, so it is treated as plain text.
DThe component must use state to display props.
Attempts:
2 left
💡 Hint
In JSX, dynamic values must be inside curly braces to be evaluated.
🧠 Conceptual
expert
2:00remaining
What happens if you modify props inside a React component?
Consider this code inside a React functional component: props.name = "Changed"; What will happen when you try to modify props like this?
AReact will throw an error because props are read-only and cannot be changed.
BThe component will update and re-render with the new prop value.
CThe prop value changes only inside the component but does not affect the parent.
DModifying props will cause the component to enter an infinite render loop.
Attempts:
2 left
💡 Hint
Props are meant to be read-only inputs to components.

Practice

(1/5)
1. What is the main purpose of props in React components?
easy
A. To handle user events like clicks
B. To store internal state within a component
C. To style components with CSS
D. To pass data from a parent component to a child component

Solution

  1. Step 1: Understand the role of props

    Props are used to send data from a parent component to a child component in React.
  2. Step 2: Differentiate props from other concepts

    State stores internal data, events handle user actions, and CSS styles components, but props specifically pass data down.
  3. Final Answer:

    To pass data from a parent component to a child component -> Option D
  4. Quick Check:

    Props = Data passing [OK]
Hint: Props always send data from parent to child [OK]
Common Mistakes:
  • Confusing props with state
  • Thinking props handle events
  • Believing props style components
2. Which of the following is the correct way to use a prop named title inside JSX?
easy
A. <h1>title</h1>
B. <h1>{title}</h1>
C. <h1>{props.title}</h1>
D. <h1>$title</h1>

Solution

  1. Step 1: Use curly braces to embed prop values in JSX

    In JSX, to show a prop value, you wrap the prop access in curly braces like {props.title}.
  2. Step 2: Understand context of prop usage

    The props object is passed to the component function, so access via {props.title}. Using {title} requires destructuring like function Comp({title}).
  3. Final Answer:

    <h1>{props.title}</h1> -> Option C
  4. Quick Check:

    Curly braces show prop values [OK]
Hint: Use curly braces { } to show props in JSX [OK]
Common Mistakes:
  • Writing prop name as plain text without braces
  • Using $ sign like in other languages
  • Using {title} without destructuring the props object
3. Given the component:
function Greeting(props) {
  return <h2>Hello, {props.name}!</h2>;
}

// Usage:
<Greeting name="Alice" />

What will be rendered on the screen?
medium
A.

Hello, {name}!

B.

Hello, Alice!

C.

Hello, props.name!

D. SyntaxError

Solution

  1. Step 1: Identify how props are passed and used

    The Greeting component receives a prop called name with value "Alice".
  2. Step 2: Understand JSX rendering with props

    The JSX uses {props.name} which inserts the string "Alice" inside the <h2> tag.
  3. Final Answer:

    <h2>Hello, Alice!</h2> -> Option B
  4. Quick Check:

    props.name = Alice [OK]
Hint: Props values appear inside curly braces in JSX output [OK]
Common Mistakes:
  • Expecting literal text {name} instead of value
  • Confusing props.name with string 'props.name'
  • Thinking this causes syntax error
4. What is wrong with this React component code?
function Welcome(props) {
  return <h1>Welcome, props.name!</h1>;
}
medium
A. props.name should be inside curly braces to render its value
B. Function name should be lowercase
C. Missing return statement
D. JSX tags must be self-closing

Solution

  1. Step 1: Check how props are used inside JSX

    The code writes props.name as plain text inside JSX, so it will render literally instead of the prop value.
  2. Step 2: Correct usage of props in JSX

    To show the value of props.name, it must be wrapped in curly braces like {props.name}.
  3. Final Answer:

    props.name should be inside curly braces to render its value -> Option A
  4. Quick Check:

    Use {props.name} to show prop value [OK]
Hint: Always wrap props in { } inside JSX [OK]
Common Mistakes:
  • Writing props.name as plain text
  • Thinking function names must be lowercase
  • Confusing JSX self-closing rules
5. You want to create a reusable Button component that shows different text based on a label prop. Which code correctly uses props to achieve this?
function Button(props) {
  return <button>???</button>;
}

Choose the correct replacement for ???.
hard
A. {props.label}
B. {label}
C. "props.label"
D. label

Solution

  1. Step 1: Understand how to access props inside the component

    The component receives props as an object, so the label prop is accessed as props.label.
  2. Step 2: Use curly braces to embed the prop value in JSX

    To show the value inside JSX, wrap props.label in curly braces: {props.label}.
  3. Final Answer:

    {props.label} -> Option A
  4. Quick Check:

    Use {props.propName} to show prop value [OK]
Hint: Use {props.propName} inside JSX to show prop values [OK]
Common Mistakes:
  • Using prop name without braces
  • Using braces without props object
  • Using quotes around prop name
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard