0
0
Reactframework~20 mins

What are props in React - Practice Questions & Exercises

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!
🧠 Conceptual
intermediate
2:00remaining
Understanding Props in React Components
In React, what are props used for in functional components?
ATo directly modify the DOM elements
BTo pass data from a parent component to a child component
CTo store local state inside a component
DTo handle side effects like data fetching
Attempts:
2 left
💡 Hint
Think about how components share information in React.
component_behavior
intermediate
2: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:
A<h1>Hello, {name}!</h1>
BError: props is undefined
C<h1>Hello, !</h1>
D<h1>Hello, Alice!</h1>
Attempts:
2 left
💡 Hint
Look at how the prop 'name' is accessed inside the component.
📝 Syntax
advanced
2: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>;
}
A{ name }
B(name)
C[name]
Dprops.name
Attempts:
2 left
💡 Hint
Destructuring props means extracting values inside the parentheses.
state_output
advanced
2: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:
ACount: 5 initially, then increases by 1 each click
BCount: 5 initially, but does not change on click
CCount: 0 initially, then increases by 1 each click
DError: Cannot read property 'initial' of undefined
Attempts:
2 left
💡 Hint
Look at how state is initialized and updated on button click.
🔧 Debug
expert
3:00remaining
Why Does This Prop Not Update?
Consider this React component:
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?
ABecause the component does not receive props correctly
BBecause props cannot change after initial render
CBecause the useEffect dependency array is empty, so it runs only once
DBecause console.log cannot show updated values inside useEffect
Attempts:
2 left
💡 Hint
Think about how useEffect dependencies control when the effect runs.