Skip to content

Commit

Permalink
Fix react-hooks/exhaustive-deps error on usePayees.ts (#4260)
Browse files Browse the repository at this point in the history
* Fix react-hooks/exhaustive-deps error on usePayees.ts

* Rename

* Release notes
  • Loading branch information
joel-jeremy authored Feb 19, 2025
1 parent 81db739 commit aea6e79
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
1 change: 0 additions & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,6 @@ export default [
'packages/desktop-client/src/components/transactions/TransactionsTable.test.jsx',
'packages/desktop-client/src/hooks/useAccounts.ts',
'packages/desktop-client/src/hooks/useCategories.ts',
'packages/desktop-client/src/hooks/usePayees.ts',
'packages/desktop-client/src/hooks/useProperFocus.tsx',
],

Expand Down
14 changes: 10 additions & 4 deletions packages/desktop-client/src/hooks/usePayees.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,21 @@ import {

import { useSelector, useDispatch } from '../redux';

import { useInitialMount } from './useInitialMount';

export function useCommonPayees() {
const dispatch = useDispatch();
const commonPayeesLoaded = useSelector(
state => state.queries.commonPayeesLoaded,
);

const isInitialMount = useInitialMount();

useEffect(() => {
if (!commonPayeesLoaded) {
if (isInitialMount && !commonPayeesLoaded) {
dispatch(getCommonPayees());
}
}, []);
}, [commonPayeesLoaded, dispatch, isInitialMount]);

return useSelector(state => state.queries.commonPayees);
}
Expand All @@ -26,11 +30,13 @@ export function usePayees() {
const dispatch = useDispatch();
const payeesLoaded = useSelector(state => state.queries.payeesLoaded);

const isInitialMount = useInitialMount();

useEffect(() => {
if (!payeesLoaded) {
if (isInitialMount && !payeesLoaded) {
dispatch(getPayees());
}
}, []);
}, [dispatch, isInitialMount, payeesLoaded]);

return useSelector(state => state.queries.payees);
}
6 changes: 6 additions & 0 deletions upcoming-release-notes/4260.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Maintenance
authors: [joel-jeremy]
---

Fix react-hooks/exhaustive-deps error on usePayees.ts

0 comments on commit aea6e79

Please sign in to comment.