Props are inputs you give to components to customize them.
Examples
A simple button component that shows text from props.
React
function Button(props) {
return <button>{props.label}</button>;
}
<Button label="Click me" />
Using destructuring to get props directly for cleaner code.
React
function Greeting({ name }) {
return <h1>Hello, {name}!</h1>;
}
<Greeting name="Alice" />
Component with children lets you put any content inside it.
React
function Card({ title, children }) {
return (
<div className="card">
<h2>{title}</h2>
<div>{children}</div>
</div>
);
}
<Card title="My Card">
<p>This is inside the card.</p>
</Card>
Sample Program
This app shows two buttons using the same reusable Button component. Each button has its own label and click action. The buttons are accessible with aria-label and keyboard friendly.
In JSX, string prop values must be in quotes or curly braces.
Step 2: Identify the error
The usage <Button label=Submit /> lacks quotes around "Submit" causing syntax error.
Final Answer:
Missing quotes around the prop value in usage -> Option C
Quick Check:
String props need quotes [OK]
Hint: String props always need quotes in JSX [OK]
Common Mistakes:
Thinking button must be wrapped in div
Believing props can't be used inside JSX
Using lowercase component names
5. You want to create a reusable List component that shows items with a custom renderItem prop function. Which approach correctly uses renderItem inside the component?
hard
A.
function List(props) {
return <ul>{
props.items.map(item => <li>{props.renderItem(item)}</li>)
}</ul>;
}
B.
function List(props) {
return <ul>{
props.items.map(props.renderItem(item))
}</ul>;
}
C.
function List(props) {
return <ul>{
props.renderItem(props.items)
}</ul>;
}
D.
function List(props) {
return <ul>{
props.items.forEach(item => props.renderItem(item))
}</ul>;
}
Solution
Step 1: Understand how to use renderItem with map
To render a list, use map to transform each item into JSX, calling renderItem for each.
Step 2: Check each option
function List(props) {
return <ul>{
props.items.map(item => <li>{props.renderItem(item)}</li>)
}</ul>;
}
correctly maps items and calls renderItem inside <li>.
function List(props) {
return <ul>{
props.items.map(props.renderItem(item))
}</ul>;
}
calls renderItem incorrectly inside map.
function List(props) {
return <ul>{
props.renderItem(props.items)
}</ul>;
}
calls renderItem once with whole array.
function List(props) {
return <ul>{
props.items.forEach(item => props.renderItem(item))
}</ul>;
}
uses forEach which returns undefined, so no output.
Final Answer:
Option A uses map and renderItem correctly inside list -> Option A
Quick Check:
Use map with renderItem for lists [OK]
Hint: Use map with renderItem inside JSX to render lists [OK]
Common Mistakes:
Using forEach instead of map for rendering
Calling renderItem outside map or with wrong argument
Passing whole array to renderItem instead of single item
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.