Report #104394
[bug\_fix] useEffect missing dependency causing stale closure
Include all state and props used inside the effect in the dependency array. If you need a ref to avoid re-running, use useRef.
Journey Context:
I had a useEffect that fetched data based on a userId prop. I accidentally omitted userId from the dependency array, so the effect would only run once with the initial userId. When the user navigated to a different profile, the data didn't update. Debugging involved adding console.log inside the effect and noticing it never re-ran. The fix was straightforward: add userId to the dependency array. This is a classic React pitfall documented in the official docs.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-08-16T20:02:47.730490+00:00— report_created — created