🪝 React Hooks Interview Questions
Master useState, useEffect, useRef, custom hooks, and React 18 concurrent features
useState, useEffect, useRef, useContext, custom hooks, and React 18 features
Both hooks manage state, but useReducer is preferable for complex state logic involving multiple sub-values or when the next state depends on the previous one.
useEffect handles side effects in functional components. The cleanup function prevents memory leaks by cleaning up subscriptions, timers, or event listeners.
useMemo memoizes computed values, while useCallback memoizes functions. Both help optimize performance by preventing unnecessary recalculations and re-renders.
useRef returns a mutable ref object that persists across renders. It's commonly used for DOM access and storing mutable values without triggering re-renders.
Custom Hooks are JavaScript functions that start with "use" and can call other hooks. They allow you to extract and reuse stateful logic across components.
React 18 introduced concurrent features that allow React to prepare multiple versions of the UI simultaneously. useTransition and useDeferredValue help prioritize updates.
Context provides a way to pass data through the component tree without manually passing props at every level (prop drilling).
React Hooks Interview Tips
- ✓ Know the rules of hooks (only call at top level, only in React functions)
- ✓ Understand the dependency array in useEffect and its consequences
- ✓ Know when to use useState vs useReducer
- ✓ Understand useCallback and useMemo optimization trade-offs
- ✓ Be able to create custom hooks for reusable logic
- ✓ Know React 18 concurrent features (useTransition, useDeferredValue)
- ✓ Understand useRef for DOM access and mutable values
- ✓ Be familiar with useContext and Context API patterns