Dev.to
7/5/2026

React 19 useCallback Dependencies in Multi-Tenant Dashboards: Why Your AI Feature Memoization Is Causing Stale Closures
Short summary
In multi-tenant dashboards, React 19's useCallback creates a hidden data-isolation bug when async API calls (like Claude) complete after a tenant switch—the stale closure retains the old tenant ID. Solution: read tenant ID from useRef at execution time instead of capturing it in the closure, maintaining memoization efficiency while preventing data leaks.
- •useCallback closures capture context at definition time, not execution time, causing data-isolation bugs in multi-tenant SaaS
- •Stale closures leak data when async operations started under one tenant complete after switching to another
- •Fix: read current context from useRef at execution time instead of capturing in closure
Generated with AI, which can make mistakes.
Is this a good recommendation for you?



