Skip to content

Commit

Permalink
fix: infinite loop in calculate button
Browse files Browse the repository at this point in the history
Signed-off-by: rare-magma <[email protected]>
  • Loading branch information
rare-magma committed Aug 10, 2024
1 parent dd5544b commit 6a2455b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
1 change: 1 addition & 0 deletions src/components/CalculateButton/CalculateButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ export function CalculateButton({
setTimeout(() => {
inputRef.current?.focus();
}, 0);
getHistory();
}}
>
<BsPlusSlashMinus aria-hidden />
Expand Down
28 changes: 16 additions & 12 deletions src/hooks/useDB.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@ export function useDB() {

return { filteredIncomes, filteredExpenses };
}

function renameBudget(event: React.ChangeEvent<HTMLInputElement>) {
if (budget && event.target.value) {
const newState = produce((draft) => {
Expand All @@ -395,18 +396,21 @@ export function useDB() {
}
}

async function getCalcHist(id: string): Promise<CalculationHistoryItem[]> {
let item;
await calcHistDB
.getItem(id)
.then((i) => {
item = i;
})
.catch((e: unknown) => {
throw e;
});
return item ?? [];
}
const getCalcHist = useCallback(
async (id: string): Promise<CalculationHistoryItem[]> => {
let item;
await calcHistDB
.getItem(id)
.then((i) => {
item = i;
})
.catch((e: unknown) => {
throw e;
});
return item ?? [];
},
[],
);

async function saveCalcHist(id: string, item: CalculationHistoryItem) {
const calcHist = await getCalcHist(id);
Expand Down

0 comments on commit 6a2455b

Please sign in to comment.