A local-first personal finance app
Fix react-hooks/exhaustive-deps error on useAccounts.ts (#4262)
Joel Jeremy Marquez10c35e18d3b2
diff --git a/eslint.config.mjs b/eslint.config.mjsindex b1d821292a..5e2136d966 100644--- a/eslint.config.mjs+++ b/eslint.config.mjs@@ -798,7 +798,7 @@ export default ['packages/desktop-client/src/components/transactions/TransactionList.jsx','packages/desktop-client/src/components/transactions/TransactionsTable.jsx','packages/desktop-client/src/components/transactions/TransactionsTable.test.jsx',- 'packages/desktop-client/src/hooks/useAccounts.ts',+ // 'packages/desktop-client/src/hooks/useAccounts.ts','packages/desktop-client/src/hooks/useCategories.ts','packages/desktop-client/src/hooks/useProperFocus.tsx',],diff --git a/packages/desktop-client/src/hooks/useAccounts.ts b/packages/desktop-client/src/hooks/useAccounts.tsindex 7fdda9a51f..f7b7119715 100644--- a/packages/desktop-client/src/hooks/useAccounts.ts+++ b/packages/desktop-client/src/hooks/useAccounts.ts@@ -4,15 +4,18 @@ import { getAccounts } from 'loot-core/client/queries/queriesSlice';import { useSelector, useDispatch } from '../redux';+import { useInitialMount } from './useInitialMount';+export function useAccounts() {const dispatch = useDispatch();const accountsLoaded = useSelector(state => state.queries.accountsLoaded);+ const isInitialMount = useInitialMount();useEffect(() => {- if (!accountsLoaded) {+ if (isInitialMount && !accountsLoaded) {dispatch(getAccounts());}- }, []);+ }, [accountsLoaded, dispatch, isInitialMount]);return useSelector(state => state.queries.accounts);}diff --git a/upcoming-release-notes/4262.md b/upcoming-release-notes/4262.mdnew file mode 100644index 0000000000..27e071d7e3--- /dev/null+++ b/upcoming-release-notes/4262.md@@ -0,0 +1,6 @@+---+category: Maintenance+authors: [joel-jeremy]+---++Fix react-hooks/exhaustive-deps error on useAccounts.ts