-
Notifications
You must be signed in to change notification settings - Fork 7
Open
Description
Several components in the project contain useEffect hooks that are missing required dependencies in their dependency arrays. This can lead to unpredictable behavior, stale closures, and bugs that are hard to trace.
Examples:
useEffect(() => {
setDescription(server?.description || "");
setTab(server?.endpoint ? TAB_ENDPOINT : TAB_SIMPLE);
setIp(server?.ip || "");
setVersion(server?.version ?? getDefaultVersion());
setEndpoint(server?.endpoint || "");
}, [server, versions]); // React Hook useEffect has a missing dependency: 'getDefaultVersion'. Either include it or remove the dependency arrayAlso run npm run lint and you'll get a bunch useEffect dep warnings
Why This Matters:
- React relies on the dependency array to determine when to re-run the effect.
- Omitting dependencies can cause effects to run with outdated values.
- This violates the [Rules of Hooks](https://reactjs.org/docs/hooks-rules.html) and may trigger warnings in strict mode or linters like
eslint-plugin-react-hooks.
Suggested Fixes:
- Audit all
useEffecthooks and ensure dependency arrays include all referenced variables. - Consider enabling
react-hooks/exhaustive-depsin ESLint to catch these automatically. - Refactor effects to avoid unnecessary re-renders or extract logic into memoized callbacks if needed.
Steps to Reproduce:
- Navigate to any component using
useEffectwith an empty dependency array. - Modify a prop or state used inside the effect.
- Observe that the effect does not re-run as expected.
#27 should be merged first before this is addressed
Metadata
Metadata
Assignees
Labels
No labels