A reusable UI component is a piece of code that defines a part of the user interface which can be used multiple times in different places, helping to keep the code simple and consistent.
Click to reveal answer
beginner
Why should we use reusable components?
Using reusable components saves time, reduces errors, and makes the app easier to maintain because you write the code once and use it many times.
Click to reveal answer
beginner
How do you pass data to a reusable component in React?
You pass data to a reusable component using props, which are like parameters that customize the component's content or behavior.
Click to reveal answer
intermediate
What is the difference between a functional component and a reusable component?
A functional component is a type of React component defined as a function. A reusable component is any component (often functional) designed to be used multiple times with different data.
Click to reveal answer
beginner
How can you make a button component reusable for different labels and actions?
Create a button component that accepts label and onClick as props. This way, you can change the text and what happens when clicked without rewriting the button.
Click to reveal answer
What is the main purpose of reusable UI components in React?
ATo write code once and use it many times
BTo make the app slower
CTo increase the file size
DTo avoid using props
✗ Incorrect
Reusable components help you write code once and use it many times, making development faster and easier.
How do you customize a reusable component's content?
ABy changing its internal code every time
BBy copying and pasting it
CBy using global variables
DBy passing props to it
✗ Incorrect
Props allow you to customize a component's content or behavior without changing its code.
Which React feature helps you create reusable UI parts?
AComponents
BEvents
CState
DHooks
✗ Incorrect
Components are the building blocks in React used to create reusable UI parts.
What type of React component is recommended for creating reusable UI components?
AClass components
BFunctional components
CInline styles
DDOM elements
✗ Incorrect
Functional components are simple and recommended for creating reusable UI components in modern React.
If you want a button component to do different things when clicked, what should you pass to it?
AA different CSS file
BA new component each time
CAn onClick function as a prop
DA global variable
✗ Incorrect
Passing an onClick function as a prop lets the button perform different actions when clicked.
Explain what reusable UI components are and why they are useful in React.
Think about how you can use the same building block many times with different details.
You got /3 concepts.
Describe how you would create a reusable button component that can show different text and perform different actions.
Focus on how props help customize the button.
You got /3 concepts.
Practice
(1/5)
1. What is the main benefit of creating reusable UI components in React?
easy
A. They automatically fix bugs
B. They make the app run faster
C. They save time and keep the app consistent
D. They replace the need for CSS styling
Solution
Step 1: Understand the purpose of reusable components
Reusable components are designed to be used multiple times, reducing repeated code.
Step 2: Identify the main benefit
Using reusable components saves development time and keeps the app's look and behavior consistent.
Final Answer:
They save time and keep the app consistent -> Option C
Quick Check:
Reusable components = save time + consistency [OK]
Hint: Reusable means use again to save time and stay consistent [OK]
Common Mistakes:
Thinking reusable components speed up app runtime
Believing they fix bugs automatically
Confusing styling with component reuse
2. Which of the following is the correct way to pass a prop named title with value "Hello" to a React component Card?
easy
A.
B.
C.
D.
Solution
Step 1: Recall JSX prop syntax
Props are passed as attributes with name=value pairs, using quotes for strings.
Step 2: Check each option
uses correct JSX syntax: title="Hello". Others have syntax errors.
Final Answer:
<Card title="Hello" /> -> Option A
Quick Check:
Props in JSX use name="value" [OK]
Hint: Props look like HTML attributes with quotes for strings [OK]
Common Mistakes:
Using curly braces without variable (Option B)
Adding extra quotes around prop name (Option C)
Using colon instead of equals (Option A)
3. Given this React component:
function Button({ label }) {
return <button>{label}</button>;
}
// Usage:
<Button label="Click me" />
What will be rendered on the page?
medium
A. label
B. Nothing will render
C. {label}
D. Click me
Solution
Step 1: Understand prop usage in the component
The component receives label as a prop and inserts it inside the button element.
Step 2: Check the usage
The component is used with label="Click me", so the button shows "Click me" text.
Final Answer:
<button>Click me</button> -> Option D
Quick Check:
Prop label = "Click me" shown inside button [OK]
Hint: Props passed show as content inside component tags [OK]
Common Mistakes:
Thinking the literal word 'label' appears
Confusing JSX expression with string
Assuming component renders nothing without explicit return
4. What is wrong with this reusable React component code?
A. The variable 'message' is not defined inside the component
B. The component does not receive props correctly
C. The usage of the component is incorrect
D. The component should return a button instead of a div
Solution
Step 1: Check how props are used inside the component
The component uses {message} but does not extract it from props.
Step 2: Identify the error
Since message is not defined or extracted, this causes a reference error.
Final Answer:
The variable 'message' is not defined inside the component -> Option A
Quick Check:
Props must be accessed via props or destructuring [OK]
Hint: Always get props from function parameter before use [OK]
Common Mistakes:
Using prop names directly without props or destructuring
Assuming usage syntax is wrong
Thinking component must return button
5. You want to create a reusable Input component that can show a label and accept user input. Which approach correctly allows customizing the label text and input placeholder using props?
hard
A. function Input() {
return (
<label>
label
<input placeholder="placeholder" />
</label>
);
}
B. function Input({ label, placeholder }) {
return (
<label>
{label}
<input placeholder={placeholder} />
</label>
);
}
C. function Input(props) {
return (
<label>
props.label
<input placeholder="props.placeholder" />
</label>
);
}
D. function Input({ label, placeholder }) {
return (
<label>
<input placeholder={label} />
{placeholder}
</label>
);
}
Solution
Step 1: Check prop usage for label and placeholder
Props should be destructured and used inside JSX expressions with curly braces.
Step 2: Verify correct placement of label and placeholder
function Input({ label, placeholder }) {
return (
<label>
{label}
<input placeholder={placeholder} />
</label>
);
} correctly places label text and uses placeholder prop inside input element.
Final Answer:
function Input({ label, placeholder }) {
return (
<label>
{label}
<input placeholder={placeholder} />
</label>
);
} -> Option B
Quick Check:
Destructure props and use inside JSX with curly braces [OK]
Hint: Destructure props and use inside JSX with curly braces [OK]
Common Mistakes:
Using prop names as plain text instead of expressions
Putting placeholder text in wrong prop
Mixing label and placeholder positions
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.