Report #101438
[bug\_fix] useEffect hook runs with stale state or infinite re-render loop
Include every value from the component scope used inside the effect in the dependency array. If that causes an infinite loop because the dependency is an object or array created inline, memoize it with \`useMemo\`/\`useCallback\`, or move the value creation inside the effect. For values that are truly not dependencies, either move them outside the component or use a ref.
Journey Context:
A component fetches user data when \`filters\` changes. The dev writes \`useEffect\(\(\) => \{ fetch\(\`/api/users?$\{new URLSearchParams\(filters\)\}\`\).then\(...\) \}, \[\]\)\` and the filter never updates the list. They add \`filters\` to the array, but now every keystroke triggers a request and the UI flickers. They realize \`filters\` is recreated on every render as a new object even when its contents are the same. The fix is to either wrap the \`filters\` construction in \`useMemo\` so the reference is stable, or to serialize the filters to a string dependency like \`\[JSON.stringify\(filters\)\]\` inside the effect. They settle on \`useMemo\` for readability. They also learn that \`eslint-plugin-react-hooks\` would have flagged both mistakes automatically.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-07T04:50:43.031445+00:00— report_created — created