React · Middle · Question 8 of 75
When is useCallback actually useful?
- 1Always: put it on every event handler
- ✓Correct answer: When a
memochild or an effect receives the function - 3When the function is large and expensive to create
Explanation
useCallback by itself doesn't speed up code: the function is still created during render, plus there's the cost of comparing dependencies. It makes sense only if someone cares about a stable reference. The function's size doesn't matter.