A React component is a small, reusable piece of code that controls part of the user interface. It can show content and handle user actions.
Click to reveal answer
beginner
What are the two main types of React components?
The two main types are functional components and class components. Functional components use functions and hooks, while class components use classes (less common now).
Click to reveal answer
beginner
Why do we use components in React?
Components help break the UI into small, manageable parts. This makes code easier to read, reuse, and maintain, like building with Lego blocks.
Click to reveal answer
beginner
How does a React component render content?
A React component returns JSX, which looks like HTML. React then shows this on the screen as part of the webpage.
Click to reveal answer
beginner
What is a functional component example in React?
Example: function Hello() { return <h1>Hello, friend!</h1>; } This shows a heading with text on the page.
Click to reveal answer
What does a React component mainly do?
ADisplays part of the user interface
BStores data in a database
CRuns server code
DManages network connections
✗ Incorrect
React components are used to display parts of the user interface.
Which syntax is used inside React components to describe UI?
AJSX
BSQL
CCSS
DXML
✗ Incorrect
JSX is a syntax that looks like HTML and is used inside React components to describe UI.
Which React component type is recommended for new code?
ANeither, use plain JavaScript
BFunctional components
CBoth are equally recommended
DClass components
✗ Incorrect
Functional components with hooks are the modern recommended way to write React components.
Why are components compared to Lego blocks?
ABecause they require batteries
BBecause they are colorful
CBecause they are made of plastic
DBecause they build UI in small, reusable pieces
✗ Incorrect
Components are like Lego blocks because they let you build UI from small, reusable parts.
What does a functional React component return?
AA CSS style
BA number
CJSX to show UI
DA database query
✗ Incorrect
Functional components return JSX, which React uses to display the UI.
Explain what a React component is and why it is useful.
Think about how you build a webpage from small parts.
You got /4 concepts.
Describe the difference between functional and class components in React.
Focus on how the component is written and used today.
You got /4 concepts.
Practice
(1/5)
1. What is a React component?
easy
A. A reusable piece of UI built with a function or class
B. A special type of variable that stores data
C. A tool to style HTML elements
D. A command to run React apps
Solution
Step 1: Understand React components
A React component is a building block of UI that can be reused multiple times.
Step 2: Identify the correct definition
Only A reusable piece of UI built with a function or class describes a reusable UI piece built with a function or class.
Final Answer:
A reusable piece of UI built with a function or class -> Option A
Quick Check:
Component = reusable UI block [OK]
Hint: Components are reusable UI parts made with functions [OK]
Common Mistakes:
Confusing components with variables
Thinking components are styling tools
Believing components are commands
2. Which of the following is the correct way to define a React functional component?
easy
A. const MyComponent = 'Hello';
B. function MyComponent() { return
Hello
; }
C. var MyComponent =
Hello
;
D. class MyComponent extends React.Component { }
Solution
Step 1: Review functional component syntax
A functional component is a function returning JSX, like function MyComponent() { return
Hello; }.
Step 2: Check each option
function MyComponent() { return
Hello
; } matches the correct syntax. var MyComponent =
Hello
; assigns JSX directly to a variable, which is not a component. const MyComponent = 'Hello'; assigns a string, not JSX. class MyComponent extends React.Component { } is a class component, not functional.
Final Answer:
function MyComponent() { return <div>Hello</div>; } -> Option B
Quick Check:
Functional component = function returning JSX [OK]
Hint: Functional components are functions returning JSX [OK]
Common Mistakes:
Assigning JSX directly to variables
Using strings instead of JSX
Confusing functional and class components
3. What will this React component render?
function Greeting() {
return <h1>Hello, world!</h1>;
}
medium
A. Nothing, because the function is not called
B. An error because of missing parentheses
C. <h1>Hello, world!</h1> displayed on the page
D. A blank page with no content
Solution
Step 1: Understand component return value
The component returns an <h1> element with text "Hello, world!" which React renders as HTML.
Step 2: Confirm rendering behavior
When used in JSX, this component will display the heading on the page. No syntax errors exist.
Final Answer:
<h1>Hello, world!</h1> displayed on the page -> Option C
Quick Check:
Return JSX renders UI [OK]
Hint: Returned JSX shows on page when component is used [OK]
Common Mistakes:
Thinking function must be called manually
Assuming missing parentheses cause error here
Believing component renders nothing by default
4. Identify the error in this React component:
function Welcome() {
return <div>Welcome to React</div>
}
medium
A. Missing semicolon after return statement
B. JSX must be wrapped in parentheses if on multiple lines
C. Function name should start with lowercase letter
D. No error, component is correct
Solution
Step 1: Check JSX syntax
The JSX is a single line and correctly returned without parentheses, which is valid.
Step 2: Verify naming and semicolon rules
Function names for components should start uppercase, which is true. Semicolons are optional in JavaScript here.
Final Answer:
No error, component is correct -> Option D
Quick Check:
Valid JSX and naming means no error [OK]
Hint: JSX on one line doesn't need parentheses [OK]
Common Mistakes:
Thinking semicolons are mandatory after return
Believing lowercase function names are required
Assuming JSX always needs parentheses
5. You want to create a reusable button component that shows different text based on a property. Which is the best way to do this?
hard
A. function Button(props) { return {props.text}; }
B. function Button() { return Click me; }
C. const Button = Click me;
D. function Button(text) { return {text}; }
Solution
Step 1: Understand passing data to components
Props are used to pass data to components. Using props.text allows dynamic button text.
Step 2: Evaluate each option
function Button(props) { return {props.text}; } correctly uses props to show different text. function Button() { return Click me; } always shows fixed text. const Button = Click me; is not a function component. function Button(text) { return {text}; } incorrectly uses a parameter instead of props object.
Final Answer:
function Button(props) { return <button>{props.text}</button>; } -> Option A
Quick Check:
Use props for dynamic content [OK]
Hint: Use props to pass dynamic text to components [OK]
Common Mistakes:
Hardcoding text inside component
Not using props object for parameters
Assigning JSX directly to variables
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.