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:
26
src/contexts/budget/hooks/useBudgetState.ts
Normal file
26
src/contexts/budget/hooks/useBudgetState.ts
Normal 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
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user