Refactor BudgetContext file

Refactor BudgetContext.tsx into smaller components and hooks to improve code readability and maintainability.
This commit is contained in:
gpt-engineer-app[bot]
2025-03-15 11:08:35 +00:00
parent 6e02282383
commit 8c403f9761
7 changed files with 404 additions and 323 deletions

View File

@@ -0,0 +1,27 @@
import React, { createContext, useContext, ReactNode } from 'react';
import { BudgetContextType } from './types';
import { useBudgetState } from './useBudgetState';
// Context 생성
const BudgetContext = createContext<BudgetContextType | undefined>(undefined);
// Context Provider 컴포넌트
export const BudgetProvider: React.FC<{ children: ReactNode }> = ({ children }) => {
const budgetState = useBudgetState();
return (
<BudgetContext.Provider value={budgetState}>
{children}
</BudgetContext.Provider>
);
};
// Context 사용을 위한 Hook
export const useBudget = () => {
const context = useContext(BudgetContext);
if (!context) {
throw new Error('useBudget must be used within a BudgetProvider');
}
return context;
};