Skip to content

fix: stabilize useEffect dependency in CodeDashboard - #105

Open
ivangarm wants to merge 1 commit into
OpenNSWM-Lab:mainfrom
ivangarm:fix/code-dashboard-useeffect-deps
Open

fix: stabilize useEffect dependency in CodeDashboard#105
ivangarm wants to merge 1 commit into
OpenNSWM-Lab:mainfrom
ivangarm:fix/code-dashboard-useeffect-deps

Conversation

@ivangarm

Copy link
Copy Markdown

I noticed that CodeDashboard has a useEffect with an empty dependency array that references loadSessions, but loadSessions is not wrapped in useCallback. This means:

  1. loadSessions is recreated on every render, but the effect captures only the initial version (stale closure).
  2. ESLint's react-hooks/exhaustive-deps rule would flag this as a missing dependency.

The fix wraps loadSessions in useCallback with an empty dependency array (it only references stable state setters), and adds loadSessions to the useEffect dependency array. This makes the hook lint-clean and ensures the interval always calls the latest version of the function.

Changes:

  • Added useCallback to the React import
  • Wrapped loadSessions in useCallback(async () => { ... }, [])
  • Changed useEffect dependency from [] to [loadSessions]

Verified by reviewing the diff and confirming that setIsLoading, setError, and setSessions are all stable state setters from useState, so the empty dependency array on useCallback is correct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant