Fix data persistence issue
Addresses a bug where budget and expense data were not persisting correctly, leading to data loss when navigating between pages.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
|
||||
import React from 'react';
|
||||
import React, { useEffect } from 'react';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { EXPENSE_CATEGORIES } from '@/constants/categoryIcons';
|
||||
import { useIsMobile } from '@/hooks/use-mobile';
|
||||
@@ -28,6 +28,22 @@ const CategoryBudgetInputs: React.FC<CategoryBudgetInputsProps> = ({
|
||||
handleCategoryInputChange(numericValue, category);
|
||||
};
|
||||
|
||||
// 컴포넌트가 마운트될 때 categoryBudgets가 로컬 스토리지에서 다시 로드되도록 이벤트 리스너 설정
|
||||
useEffect(() => {
|
||||
const handleStorageChange = () => {
|
||||
// 부모 컴포넌트에서 데이터가 업데이트되므로 별도 처리 필요 없음
|
||||
console.log('카테고리 예산 데이터 변경 감지됨');
|
||||
};
|
||||
|
||||
window.addEventListener('categoryBudgetsUpdated', handleStorageChange);
|
||||
window.addEventListener('storage', handleStorageChange);
|
||||
|
||||
return () => {
|
||||
window.removeEventListener('categoryBudgetsUpdated', handleStorageChange);
|
||||
window.removeEventListener('storage', handleStorageChange);
|
||||
};
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div className="space-y-2 w-full">
|
||||
{EXPENSE_CATEGORIES.map(category => (
|
||||
|
||||
Reference in New Issue
Block a user