Skip to content

Commit

Permalink
fix: useffect dependencies on saveBudget()
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 6, 2024
1 parent 04354a1 commit 94e9f79
Showing 1 changed file with 28 additions and 28 deletions.
56 changes: 28 additions & 28 deletions src/hooks/useDB.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { produce } from "immer";
import Papa from "papaparse";
import React, { useEffect, useState } from "react";
import React, { useCallback, useEffect, useState } from "react";
import { Option } from "react-bootstrap-typeahead/types/types";
import { useParams } from "react-router-dom";
import { Budget } from "../components/Budget/Budget";
Expand Down Expand Up @@ -422,34 +422,34 @@ export function useDB() {
});
}

function saveBudget(budget: Budget | undefined) {
if (!budget) return;
let list: Budget[] = [];
budgetsDB
.setItem(budget.id, budget)
.then(() => {
budgetsDB
.iterate((value) => {
list = list.concat(value as Budget);
})
.then(() => {
setBudgetList(list);
setBudgetNameList(createBudgetNameList(list));
setNeedReload(true);
})
.catch((e: unknown) => {
throw e;
});
})
.catch((e: unknown) => {
throw e;
});
}
const saveBudget = useCallback(
(budget: Budget | undefined) => {
if (!budget) return;
let list: Budget[] = [];
budgetsDB
.setItem(budget.id, budget)
.then(() => {
budgetsDB
.iterate((value) => {
list = list.concat(value as Budget);
})
.then(() => {
setBudgetList(list);
setBudgetNameList(createBudgetNameList(list));
setNeedReload(true);
})
.catch((e: unknown) => {
throw e;
});
})
.catch((e: unknown) => {
throw e;
});
},
[setBudgetList, setBudgetNameList, setNeedReload],
);

// biome-ignore lint/correctness/useExhaustiveDependencies: <explanation>
useEffect(() => {
saveBudget(budget);
}, [budget]);
useEffect(() => void saveBudget(budget), [budget, saveBudget]);

return {
createBudget,
Expand Down

0 comments on commit 94e9f79

Please sign in to comment.