Props are inputs to React components. They are used to pass data from a parent component to a child component, like giving a gift to a friend.
Click to reveal answer
beginner
How do you pass a prop named title with value "Hello" to a component Greeting?
You write: <Greeting title="Hello" />. This sends the value "Hello" to the Greeting component as a prop called title.
Click to reveal answer
beginner
How does a functional component access props?
A functional component receives props as its first argument. For example: <code>function Greeting(props) { return <h1>{props.title}</h1>; }</code>
Click to reveal answer
intermediate
What happens if you don't pass a required prop to a component?
If a component expects a prop but you don't pass it, the prop will be undefined. This might cause errors or missing content unless you provide a default value.
Click to reveal answer
beginner
Can props be changed inside a child component?
No, props are read-only inside the child component. They are like a gift you receive but cannot change. To change data, use state or callbacks.
Click to reveal answer
How do you pass multiple props to a React component?
A<Component (name="John", age=30) />
B<Component props={{name: "John", age: 30}} />
C<Component name="John" age={30} />
D<Component>name="John" age={30}</Component>
✗ Incorrect
You pass multiple props by listing them inside the component tag like <Component name="John" age={30} />.
Inside a functional component, how do you access a prop called color?
AgetProp('color')
Bthis.color
Ccolor()
Dprops.color
✗ Incorrect
Props are accessed via the props object, so use props.color.
What is the correct way to provide a default value for a prop in a functional component?
AYou cannot set default props in functional components
BUse default parameters: function Comp({ title = 'Hi' }) { ... }
CUse this.defaultProps = { title: 'Hi' }
DSet props.title = 'Hi' inside the component
✗ Incorrect
You can use default parameters in the function signature to set default prop values.
Can a child component modify the props it receives?
ANo, props are read-only
BYes, props can be changed anytime
COnly if you use setState
DOnly if props are passed as objects
✗ Incorrect
Props are read-only and cannot be changed inside the child component.
Which of these is a valid way to pass a number prop called count with value 5?
A<Counter count={5} />
B<Counter count="5" />
C<Counter count='5' />
D<Counter count=(5) />
✗ Incorrect
To pass a number, use curly braces: count={5}. Quotes pass strings.
Explain how props work in React and why they are important.
Think about how you give information to a friend to do something.
You got /3 concepts.
Describe how to pass and access multiple props in a functional React component.
Imagine sending a letter with several details and reading them inside.
You got /3 concepts.
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 local state inside a component
C. To pass data from a parent component to a child component
D. To style components with CSS
Solution
Step 1: Understand the role of props
Props are used to send data from one component to another, specifically from parent to child.
Step 2: Differentiate props from other React features
State stores local data, events handle interactions, and CSS styles components, but props specifically pass data down.
Final Answer:
To pass data from a parent component to a child component -> Option C
Quick Check:
Props = data passing [OK]
Hint: Props always send data down 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 pass a prop named title with value "Hello" to a component Header?
easy
A.
B.
C.
D.
Solution
Step 1: Recall JSX prop syntax
Props are passed like HTML attributes: name="value" or name={expression}.
Step 2: Check each option
uses correct string syntax. misses quotes around string. uses invalid quotes. uses colon which is invalid in JSX.