Ensure daily and weekly budgets are calculated correctly based on the monthly budget, and that the monthly budget is consistent across the app.
30 lines
908 B
TypeScript
30 lines
908 B
TypeScript
|
|
import { useState } from 'react';
|
|
import { BudgetData, BudgetPeriod } from '../types';
|
|
import { safelyLoadBudgetData } from '../budgetUtils';
|
|
|
|
/**
|
|
* 예산 데이터의 기본 상태를 관리하는 훅
|
|
*/
|
|
export const useBudgetState = () => {
|
|
// 초기 데이터 로드 시 safelyLoadBudgetData 함수 사용
|
|
const initialBudgetData = safelyLoadBudgetData();
|
|
console.log('초기 예산 데이터 로드:', initialBudgetData);
|
|
|
|
const [budgetData, setBudgetData] = useState<BudgetData>(initialBudgetData);
|
|
const [selectedTab, setSelectedTab] = useState<BudgetPeriod>("daily"); // 초기값은 daily
|
|
const [isInitialized, setIsInitialized] = useState(false);
|
|
const [lastUpdateTime, setLastUpdateTime] = useState(0);
|
|
|
|
return {
|
|
budgetData,
|
|
setBudgetData,
|
|
selectedTab,
|
|
setSelectedTab,
|
|
isInitialized,
|
|
setIsInitialized,
|
|
lastUpdateTime,
|
|
setLastUpdateTime
|
|
};
|
|
};
|