A functional component is a JavaScript function that returns React elements to describe what should appear on the screen. It is simple and uses hooks for state and side effects.
Click to reveal answer
beginner
How do you define a functional component that shows a greeting message?
You write a function that returns JSX. For example:<br><pre>function Greeting() {<br> return <h1>Hello!</h1>;<br>}</pre>
Click to reveal answer
intermediate
Why do we use hooks like useState in functional components?
Hooks like useState let functional components remember information (state) between renders, making them interactive without needing class components.
Click to reveal answer
intermediate
What is the difference between a functional component and a class component?
Functional components are simpler functions returning JSX and use hooks for features. Class components use ES6 classes and lifecycle methods. Functional components are now preferred.
Click to reveal answer
intermediate
Can functional components have side effects like fetching data? How?
Yes, by using the useEffect hook inside the functional component, you can run code after rendering, like fetching data or updating the document title.
Click to reveal answer
What does a functional component in React return?
AA string
BJSX elements
CA number
DA class instance
✗ Incorrect
Functional components return JSX elements that describe the UI.
Which hook is used to add state to a functional component?
AuseState
BuseContext
CuseEffect
DuseReducer
✗ Incorrect
useState is the hook that lets you add state to functional components.
How do you write a simple functional component named Hello that shows 'Hi'?
useState is a React hook and must be imported explicitly from 'react'.
Step 2: Verify other code parts
The return statement and JSX syntax are correct; calling setCount in onClick is valid.
Final Answer:
useState is not imported from React -> Option C
Quick Check:
Hooks require import from React [OK]
Hint: Always import useState from React before using it [OK]
Common Mistakes:
Forgetting to import useState
Thinking setCount can't be called in event handlers
Assuming JSX syntax errors without checking imports
5. You want to create a functional component that shows a list of items passed as props and highlights the selected item on click. Which approach correctly uses hooks and props together?
hard
A. Use useState to track selected item and map props.items to render list with onClick handlers updating state
B. Use class component with this.state and this.props to manage selected item and render list
C. Use useEffect to directly modify props.items and highlight selected item
D. Render props.items without state and rely on CSS :hover to highlight selection
Solution
Step 1: Understand state and props roles
Props provide data (items), state tracks UI changes (selected item).
Step 2: Choose correct React hooks usage
useState is used to track selected item; mapping props.items with onClick updates state correctly.
Step 3: Evaluate other options
Class components are outdated here; useEffect should not modify props; CSS :hover can't track selection state.
Final Answer:
Use useState to track selected item and map props.items to render list with onClick handlers updating state -> Option A
Quick Check:
State for selection + props for data = Use useState to track selected item and map props.items to render list with onClick handlers updating state [OK]
Hint: Use useState for UI changes, props for data input [OK]
Common Mistakes:
Trying to modify props directly
Using class components instead of functional with hooks
Relying on CSS hover for persistent selection
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.