Lovable ui

React Hook Dependency Warning - Stale Closures

ESLint shows 'missing dependency in useEffect' or 'exhaustive-deps' warning. Code works but warning suggests adding dependencies. Adding dependencies causes infinite loops. Stale closures reference old values.

React hooks require explicit dependency arrays to track when effects should re-run. Missing dependencies cause stale closures; extra ones cause infinite loops.

Error Messages You Might See

React Hook useEffect has a missing dependency Exhaustive-deps Stale closure
React Hook useEffect has a missing dependencyExhaustive-depsStale closure

Common Causes

  1. Variable used in effect but not in dependencies array
  2. Function reference changes every render
  3. Object/array in dependencies (equality always false)
  4. Suppressing warning with eslint-disable instead of fixing
  5. Not understanding effect lifecycle

How to Fix It

Add all dependencies:

const [count, setCount] = useState(0);

useEffect(() => {
  console.log(count); // use count
}, [count]); // add to deps

Memoize dependencies to prevent re-creates:

const config = useMemo(() => ({ value: 10 }), []);
useEffect(() => {
  console.log(config.value);
}, [config]);

Real developers can help you.

Franck Plazanet Franck Plazanet I am a Strategic Engineering Leader with over 8 years of experience building high-availability enterprise systems and scaling high-performing technical teams. My focus is on bridging the gap between complex technology and business growth. Core Expertise: πŸš€ Leadership: Managing and coaching teams of 15+ engineers, fostering a culture of accountability and continuous improvement. πŸ—οΈ Architecture: Enterprise Core Systems, Multi-system Integration (ERP/API/ETL), and Core Database Structure. ☁️ Cloud & Scale: AWS Expert; architected systems handling 10B+ monthly requests and managing 100k+ SKUs. πŸ“ˆ Business Impact: Aligning tech strategy with P&L goals to drive $70k+ in monthly recurring revenue. I thrive on "out-of-the-box" thinking to solve complex technical bottlenecks and am always looking for ways to use automation to improve business productivity. Kingsley Omage Kingsley Omage Fullstack software engineer passionate about AI Agents, blockchain, LLMs. Pratik Pratik SWE with 15+ years of experience building and maintaining web apps and extensive BE infrastructure Milan Surelia Milan Surelia Milan Surelia is a Mobile App Developer with 5+ years of experience crafting scalable, cross-platform apps at 7Span and Meticha. At 7Span, he engineers feature-rich Flutter apps with smooth performance and modern UI. As the Co-Founder of Meticha, he builds open-source tools and developer-focused products that solve real-world problems. Expertise: πŸ’‘ Developing cross-platform apps using Flutter, Dart, and Jetpack Compose for Android, iOS, and Web. πŸ–‹οΈ Sharing insights through technical writing, blogging, and open-source contributions. 🀝 Collaborating closely with designers, PMs, and developers to build seamless mobile experiences. Notable Achievements: 🎯 Revamped the Vepaar app into Vepaar Store & CRM with a 2x performance boost and smoother UX. πŸš€ Launched Compose101 β€” a Jetpack Compose starter kit to speed up Android development. 🌟 Open source contributions on Github & StackOverflow for Flutter & Dart πŸŽ–οΈ Worked on improving app performance and user experience with smart solutions. Milan is always happy to connect, work on new ideas, and explore the latest in technology. Bastien Labelle Bastien Labelle Full stack dev w/ 20+ years of experience Richard McSorley Richard McSorley Full-Stack Software Engineer with 8+ years building high-performance applications for enterprise clients. Shipped production systems at Walmart (4,000+ stores), Cigna (20M+ users), and Arkansas Blue Cross. 5 patents in retail/supply chain tech. Currently focused on AI integrations, automation tools, and TypeScript-first architectures. Sage Fulcher Sage Fulcher Hey I'm Sage! Im a Boston area software engineer who grew up in South Florida. Ive worked at a ton of cool places like a telehealth kidney care startup that took part in a billion dollar merger (Cricket health/Interwell health), a boutique design agency where I got to work on a ton of exciting startups including a photography education app, a collegiate Esports league and more (Philosophie), a data analytics as a service startup in Cambridge (MA) as well as at Phillips and MIT Lincoln Lab where I designed and developed novel network security visualizations and analytics. I've been writing code and furiously devoted to using computers to make people’s lives easier for about 17 years. My degree is in making computers make pretty lights and sounds. Outside of work I love hip hop, the Celtics, professional wrestling, magic the gathering, photography, drumming, and guitars (both making and playing them) BurnHavoc BurnHavoc Been around fixing other peoples code for 20 years. Nam Tran Nam Tran 10 years as fullstack developer Matthew Jordan Matthew Jordan I've been working at a large software company named Kainos for 2 years, and mainly specialise in Platform Engineering. I regularly enjoy working on software products outside of work, and I'm a huge fan of game development using Unity. I personally enjoy Python & C# in my spare time, but I also specialise in multiple different platform-related technologies from my day job.

You don't need to be technical. Just describe what's wrong and a verified developer will handle the rest.

Get Help

Frequently Asked Questions

What causes infinite loops?

Dependency that always changes: new object, array, or function created on each render.

When can I ignore exhaustive-deps?

Rarely. Instead fix root cause: memoize deps with useMemo or useCallback.

Related Lovable Issues

Can't fix it yourself?
Real developers can help.

You don't need to be technical. Just describe what's wrong and a verified developer will handle the rest.

Get Help