🪝 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
Explain the difference between useState and useReducer hooks
MediumBoth 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.
What is the useEffect hook and explain its cleanup function?
MediumuseEffect handles side effects in functional components. The cleanup function prevents memory leaks by cleaning up subscriptions, timers, or event listeners.
How do useMemo and useCallback work? When should you use them?
MediumuseMemo memoizes computed values, while useCallback memoizes functions. Both help optimize performance by preventing unnecessary recalculations and re-renders.
Explain the useRef hook and its use cases
MediumuseRef returns a mutable ref object that persists across renders. It's commonly used for DOM access and storing mutable values without triggering re-renders.
What are Custom Hooks and how do you create them?
MediumCustom Hooks are JavaScript functions that start with "use" and can call other hooks. They allow you to extract and reuse stateful logic across components.
What are React 18's concurrent features (useTransition, useDeferredValue)?
HardReact 18 introduced concurrent features that allow React to prepare multiple versions of the UI simultaneously. useTransition and useDeferredValue help prioritize updates.
What is React Context API and when should you use it?
MediumContext 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