What is useEffect used for and how do you avoid common pitfalls with dependency arrays?
Updated Apr 23, 2026
Short answer
useEffect runs side effects after render—data fetching, subscriptions, DOM sync, logging. The dependency array tells React when to re-run: [] runs once after mount (in Strict Mode dev, setup may run twice intentionally), omitting deps runs every render, and listing values reruns when they change by Object.is.
Deep explanation
Return a cleanup function to unsubscribe or cancel work. Pitfalls include stale closures from missing deps, infinite loops from unstable object/array identities created inline, and fetching without cancellation for rapid navigations.
Unlock with a Pro subscription to view this section.
View pricingReal-world example
No real-world example available yet.
Unlock with a Pro subscription to view this section.
Upgrade to ProCommon mistakes
No common mistakes listed yet.
Unlock with a Pro subscription to view this section.
Upgrade to ProFollow-up questions
No follow-up questions available yet.
Unlock with a Pro subscription to view this section.
Upgrade to Pro