A reusable component is a piece of UI code that can be used multiple times in different parts of an app, helping to avoid repetition and keep code clean.
Click to reveal answer
beginner
How do props help in making React components reusable?
Props let you pass different data to the same component, so it can show different content or behave differently each time it is used.
Click to reveal answer
intermediate
Why should reusable components be small and focused?
Small, focused components are easier to understand, test, and reuse in many places without extra work or confusion.
Click to reveal answer
beginner
What is the difference between a reusable component and a one-time component?
A reusable component is designed to be used many times with different data, while a one-time component is built for a single specific use.
Click to reveal answer
beginner
Give an example of a simple reusable React component.
Example: A Button component that takes props like 'label' and 'onClick' so it can be used anywhere with different text and actions.
Click to reveal answer
What makes a React component reusable?
AIt accepts props to customize its content or behavior
BIt uses state internally only
CIt is written as a class component
DIt is only used once in the app
✗ Incorrect
Reusable components accept props so they can show different content or behave differently each time.
Which of these is a benefit of reusable components?
AWriting more code for each use
BMaking the app slower
CAvoiding repetition and making code easier to maintain
DLimiting the app to one style
✗ Incorrect
Reusable components help avoid repeating code and make maintenance easier.
How do you pass data to a reusable React component?
AUsing HTML tags
BUsing props
CUsing CSS
DUsing global variables
✗ Incorrect
Props are the way to pass data into React components.
What should a reusable component focus on?
ABeing very complex
BDoing many unrelated tasks
CHaving no props
DBeing small and focused on one job
✗ Incorrect
Small, focused components are easier to reuse and maintain.
Which of these is NOT a good practice for reusable components?
AHardcoding content inside the component
BKeeping components small
CUsing props for customization
DUsing the component multiple times
✗ Incorrect
Hardcoding content reduces reusability because the component can't adapt to different data.
Explain what reusable components are and why they are useful in React.
Think about how using the same piece of UI code in many places helps save time.
You got /3 concepts.
Describe how you would create a simple reusable button component in React.
Focus on how props let you change the button text and action.
You got /3 concepts.
Practice
(1/5)
1. What is the main benefit of using reusable components in React?
easy
A. They make your app run faster by default
B. They let you write less code and keep your app organized
C. They automatically fix bugs in your code
D. They prevent users from clicking buttons
Solution
Step 1: Understand the purpose of reusable components
Reusable components are designed to be used multiple times to avoid repeating code.
Step 2: Identify the main benefit
Using reusable components helps keep the app organized and reduces the amount of code you write.
Final Answer:
They let you write less code and keep your app organized -> Option B
Quick Check:
Reusable components = less code + organized app [OK]
Hint: Reusable means use again to save code and stay organized [OK]
Common Mistakes:
Thinking reusable components speed up the app automatically
Believing they fix bugs without coding
Confusing reusable components with user interaction controls
2. Which of the following is the correct way to pass a prop named title with value "Hello" to a reusable component Card?
easy
A. <Card title=Hello />
B. <Card title={Hello} />
C. <Card "Hello"=title />
D. <Card title="Hello" />
Solution
Step 1: Recall JSX prop syntax
Props are passed as attributes with name and value inside quotes or curly braces for expressions.
Step 2: Check each option
<Card title="Hello" /> uses correct syntax: title="Hello". <Card title={Hello} /> misses quotes around string. <Card title=Hello /> lacks quotes or braces. <Card "Hello"=title /> has incorrect attribute format.
Final Answer:
<Card title="Hello" /> -> Option D
Quick Check:
Props need name="value" syntax [OK]
Hint: Props look like HTML attributes with quotes [OK]
Common Mistakes:
Forgetting quotes around string prop values
Using curly braces without variables
Swapping prop name and value order
3. What will be the output of this React component usage?
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.