Refactor: Split useBudgetDataState hook

Splits the `useBudgetDataState` hook into smaller, more manageable hooks for state management, data loading, and event handling. This improves code organization and maintainability while preserving existing functionality.
This commit is contained in:
gpt-engineer-app[bot]
2025-03-22 11:01:19 +00:00
parent 8aabb2fa9c
commit d1a9b9f89f
5 changed files with 289 additions and 176 deletions

View File

@@ -0,0 +1,26 @@
import { useState } from 'react';
import { BudgetData, BudgetPeriod } from '../types';
import { safelyLoadBudgetData } from '../budgetUtils';
/**
* 예산 데이터의 기본 상태를 관리하는 훅
*/
export const useBudgetState = () => {
// 초기 데이터 로드 시 safelyLoadBudgetData 함수 사용
const [budgetData, setBudgetData] = useState<BudgetData>(safelyLoadBudgetData());
const [selectedTab, setSelectedTab] = useState<BudgetPeriod>("daily");
const [isInitialized, setIsInitialized] = useState(false);
const [lastUpdateTime, setLastUpdateTime] = useState(0);
return {
budgetData,
setBudgetData,
selectedTab,
setSelectedTab,
isInitialized,
setIsInitialized,
lastUpdateTime,
setLastUpdateTime
};
};