React Component Lifecycle & useEffect Quiz – 20 Questions with Answers
20 questions · 15 min · Medium
Test your knowledge of creating and using custom Hooks in React, including reusable stateful logic, naming conventions, useState, useEffect, and Hook rules.
No sign-up needed · Last updated:
Score: 0 00:00
Create a free account to keep your scores and track your progress. It is optional.
20 questions · 15 min · Medium
15 questions · 12 min · Medium
15 questions · 12 min · Medium
15 questions · 12 min · Medium
15 questions · 12 min · Medium
15 questions · 12 min · Medium
A. To create reusable stateful logic
Custom Hooks allow developers to reuse stateful logic across multiple React components.
B. It must start with the word use
Custom Hooks should start with use, such as useFetch or useForm, so React and developers can recognize them as Hooks.
C. useFetch
A custom Hook name should begin with use, making useFetch a valid name.
A. Yes
Custom Hooks can call built-in Hooks such as useState, useEffect, useMemo, and other Hooks.
B. Stateful logic
Custom Hooks are designed to share reusable stateful behavior rather than share rendered UI.
B. A custom Hook can return values, objects, arrays, or functions
A custom Hook can return whatever data or functions are useful to the component using it.
A. useState
useState is commonly used inside custom Hooks when reusable logic needs to manage state.
A. useEffect
useEffect can be used inside custom Hooks to perform side effects such as fetching data, subscribing to events, or interacting with external systems.
B. Inside React function components or other custom Hooks
Custom Hooks follow the Rules of Hooks and can be called from function components or other custom Hooks.
C. Hooks should be called at the top level
Hooks should be called at the top level of a function component or custom Hook, not inside conditions, loops, or nested functions.
B. They reduce duplication of stateful logic
Custom Hooks make it easier to reuse common stateful behavior instead of duplicating the same logic across components.
B. No, each Hook call has its own state
Custom Hooks share logic, not state itself. Each component calling the Hook receives its own independent state.
A. function useCounter() { const [count, setCount] = useState(0); return { count, setCount }; }
useCounter follows the custom Hook naming convention, uses useState correctly, and returns reusable state-related values.
A. Yes
Custom Hooks can call other custom Hooks, allowing reusable logic to be composed into more specialized Hooks.
B. Custom Hooks are primarily for sharing logic, while components are responsible for rendering UI
Custom Hooks encapsulate reusable logic and stateful behavior, while React components use that logic to render the user interface.