What is the difference between useEffect and useMemo in React?
A common fresher and junior frontend question used to test rendering, side effects, and performance basics.
0
Asked by KASA community7 Jul 20261 view
KASA answer
useEffect is used for side effects such as API calls, subscriptions, timers, analytics, or manually interacting with browser APIs. It runs after React has committed the render. useMemo is used to memoize the result of a calculation so that React does not recompute it on every render unless its dependencies change.
A good interview answer should mention that useMemo should not be used for every value. It is useful when the calculation is expensive or when stable reference identity helps avoid unnecessary child renders. useEffect should not be used to calculate values that can be derived during render.
Cover these points
useEffect is for side effects after render.
useMemo is for memoizing calculated values.
Both depend on dependency arrays.
Do not use useEffect for derived state when normal render calculation is enough.