Bird
Raised Fist0
Reactframework~10 mins

What are props in React - Interactive Quiz & Practice

Choose your learning style10 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to pass a prop named name with value "Alice" to the Greeting component.

React
function App() {
  return <Greeting [1] />;
}
Drag options to blanks, or click blank then click option'
Avalue="Alice"
Bname="Alice"
Cprop="Alice"
Dtext="Alice"
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect attribute names like 'value' or 'prop' instead of the prop name.
2fill in blank
medium

Complete the code to access the name prop inside the Greeting component.

React
function Greeting([1]) {
  return <h1>Hello, {name}!</h1>;
}
Drag options to blanks, or click blank then click option'
Aname
Bprops
C{name}
Dprops.name
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'props' without destructuring and then trying to use 'name' directly.
3fill in blank
hard

Fix the error in the code to correctly display the name prop.

React
function Greeting(props) {
  return <h1>Hello, [1]!</h1>;
}
Drag options to blanks, or click blank then click option'
Aprops[name]
Bname
Cprops.name
Dprops->name
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to use 'name' directly without destructuring or accessing it from props.
4fill in blank
hard

Fill both blanks to pass two props firstName and age to the User component.

React
function App() {
  return <User [1] [2] />;
}
Drag options to blanks, or click blank then click option'
AfirstName="Bob"
Bage={30}
Cname="Bob"
Dyears={30}
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong prop names or passing numbers as strings.
5fill in blank
hard

Fill all three blanks to create a Profile component that receives props and displays them.

React
function Profile([1], [2], [3]) {
  return (
    <div>
      <h2>{firstName} {lastName}</h2>
      <p>Age: {age}</p>
    </div>
  );
}
Drag options to blanks, or click blank then click option'
AfirstName
Bage
ClastName
Dprops
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'props' instead of destructuring individual props.

Practice

(1/5)
1. What are props in React?
easy
A. Data passed from a parent component to a child component
B. A way to store component state internally
C. Functions that update the component's state
D. A method to style components

Solution

  1. Step 1: Understand the role of props

    Props are used to send data from a parent component down to a child component in React.
  2. Step 2: Differentiate props from state and methods

    Props are not for storing state or styling; they are inputs like function arguments.
  3. Final Answer:

    Data passed from a parent component to a child component -> Option A
  4. Quick Check:

    Props = Parent to child data [OK]
Hint: Props are like function arguments passed down [OK]
Common Mistakes:
  • Confusing props with state
  • Thinking props change inside the child
  • Believing props are used for styling
2. Which of the following is the correct way to pass a prop named title with value "Hello" to a component Greeting?
easy
A.
B.
C.
D.

Solution

  1. Step 1: Recognize JSX prop syntax

    Props are passed as attributes with key-value pairs inside JSX tags, using quotes for strings.
  2. Step 2: Check each option's syntax

    correctly uses title="Hello". misses the key, C uses unquoted value, D misses quotes.
  3. Final Answer:

    <Greeting title="Hello" /> -> Option D
  4. Quick Check:

    Props syntax = key="value" [OK]
Hint: Props look like HTML attributes with quotes [OK]
Common Mistakes:
  • Omitting the prop name
  • Not quoting string values
  • Using curly braces without variables
3. Given this component:
function Welcome(props) {
  return <h1>Hello, {props.name}!</h1>;
}

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

What will be rendered on the screen?
medium
A. Hello, props.name!
B. Hello, !
C. Hello, Alice!
D. Error: props is undefined

Solution

  1. Step 1: Identify how props are used in the component

    The component uses props.name inside JSX to display the passed name.
  2. Step 2: Check the usage of the component

    The component is called with name="Alice", so props.name equals "Alice".
  3. Final Answer:

    Hello, Alice! -> Option C
  4. Quick Check:

    props.name = Alice [OK]
Hint: Props values appear where you use {props.key} [OK]
Common Mistakes:
  • Printing the literal string 'props.name'
  • Forgetting to pass the prop
  • Assuming props is undefined
4. What is wrong with this React component usage?
function Message(props) {
  return <p>{props.text}</p>;
}

// Usage:
<Message text=Hello />
medium
A. The function should return a string, not JSX
B. The prop value Hello should be in quotes
C. Props cannot be used inside <p> tags
D. The component name should be lowercase

Solution

  1. Step 1: Check the prop syntax in usage

    The prop text=Hello is missing quotes around the string value.
  2. Step 2: Recall JSX rules for string props

    String props must be quoted like text="Hello" or wrapped in curly braces if a variable.
  3. Final Answer:

    The prop value Hello should be in quotes -> Option B
  4. Quick Check:

    String props need quotes [OK]
Hint: Always quote string props in JSX [OK]
Common Mistakes:
  • Leaving string props unquoted
  • Using lowercase component names
  • Misunderstanding JSX return types
5. You want to create a reusable Button component that shows different labels based on props. Which approach correctly uses props to achieve this?
function Button(props) {
  return <button>{props.label}</button>;
}

// Usage:
<Button label="Save" />
<Button label="Cancel" />
hard
A. This approach works because props.label changes the button text dynamically
B. This approach is wrong because props cannot be used inside button tags
C. You must use state instead of props to change button labels
D. Button labels must be hardcoded inside the component

Solution

  1. Step 1: Understand props usage for dynamic content

    Props allow passing different values to the same component to show varied content.
  2. Step 2: Verify the example usage

    The Button component uses props.label inside the button, and different labels are passed in usage.
  3. Final Answer:

    This approach works because props.label changes the button text dynamically -> Option A
  4. Quick Check:

    Props enable reusable components [OK]
Hint: Use props to customize component content easily [OK]
Common Mistakes:
  • Thinking props can't change displayed text
  • Confusing props with state for static labels
  • Hardcoding values inside components
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