All Templates
React Hooks Deep Dive
Master React hooks with questions on useState, useEffect, useContext, useMemo, useCallback, and custom hooks. Covers common pitfalls and best practices.
MEDIUM7 questions12 minProgramming
Question Preview
1.What happens when you call setState inside useEffect without a dependency array?
It causes an infinite re-render loop
It only runs once on mount
It throws a compile-time error
React batches the updates and runs only once
MEDIUMMultiple Choice
2.What is the primary purpose of the useEffect cleanup function?
To clean up side effects like subscriptions and timers when the component unmounts or before re-running the effect
To reset the component's state to its initial value
To clear the browser cache when navigating away
To remove the component from the DOM manually
MEDIUMMultiple Choice
3.What is the difference between useMemo and useCallback?
useMemo memoizes a computed value; useCallback memoizes a function reference
useMemo is for synchronous operations; useCallback is for async operations
They are identical and interchangeable
useCallback runs the function immediately; useMemo defers execution
MEDIUMMultiple Choice
+ 4 more questions included in the full template