Backend Engineering, Frontend Engineering
Senior
programming
In which scenario would you prefer useMemo over useCallback in React?
A) When you want to memoize a value.
B) When you want to memoize a function.
C) Both are used interchangeably.
D) When you need to prevent re-renders.
```
## Approach
useMemo is used to memoize values and optimize computations, while useCallback is for memoizing functions. It's important to choose the right hook based on the use case.
## Complexity
**Time:** O(...) (depends on the calculation being memoized)
**Space:** O(...) (memorization can consume additional memory)
## Trade-offs
- Choosing between the two for optimization must consider the render frequency.
```
Trusted by 100+ professionals preparing for interviews
Trusted by 100+ professionals
50+ Company Question Banks
5+ Supported Languages
Practice More Questions Like This
Generate unlimited interview questions with structured answers, code runner, and AI-powered walkthroughs.
Get Started Free
More Backend Engineering, Frontend Engineering Interview Prep
In React, what is the purpose of the useEffect hook?
Backend Engineering, Frontend Engineering · Senior
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.