optimize boot sequnse

This commit is contained in:
hansoo
2025-03-19 07:27:10 +09:00
parent ab3bcbdc63
commit 2ec913c6c0
12 changed files with 224 additions and 180 deletions

View File

@@ -1,29 +1,8 @@
import React, { createContext, useContext } from 'react';
import React from 'react';
import { useBudgetState } from './useBudgetState';
import { BudgetData, BudgetPeriod, Transaction } from './types';
// 컨텍스트 인터페이스 정의
interface BudgetContextType {
transactions: Transaction[];
selectedTab: BudgetPeriod;
setSelectedTab: (tab: BudgetPeriod) => void;
budgetData: BudgetData;
categoryBudgets: Record<string, number>;
getCategorySpending: () => Array<{
title: string;
current: number;
total: number;
}>;
addTransaction: (transaction: Transaction) => void;
updateTransaction: (transaction: Transaction) => void;
deleteTransaction: (id: string) => void;
handleBudgetGoalUpdate: (type: BudgetPeriod, amount: number, newCategoryBudgets?: Record<string, number>) => void;
resetBudgetData?: () => void; // 선택적 필드로 추가
}
// 컨텍스트 생성
const BudgetContext = createContext<BudgetContextType | undefined>(undefined);
import { BudgetContext, BudgetContextType } from './useBudget';
import { BudgetPeriod } from './types';
// 컨텍스트 프로바이더 컴포넌트
export const BudgetProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => {
@@ -36,13 +15,7 @@ export const BudgetProvider: React.FC<{ children: React.ReactNode }> = ({ childr
);
};
// 훅을 통한 컨텍스트 접근
export const useBudget = (): BudgetContextType => {
const context = useContext(BudgetContext);
if (context === undefined) {
throw new Error('useBudget must be used within a BudgetProvider');
}
return context;
};
// useBudget 훅은 useBudget.ts 파일로 이동했습니다
export { useBudget, BudgetContextType } from './useBudget';
export type { BudgetPeriod } from './types';