Fix: App crashing on launch
Investigate and resolve the issue causing the application to crash during startup.
This commit is contained in:
@@ -16,8 +16,8 @@ export const useTransactionState = () => {
|
||||
useEffect(() => {
|
||||
try {
|
||||
const storedTransactions = loadTransactionsFromStorage();
|
||||
console.log('로컬 스토리지에서 트랜잭션 로드:', storedTransactions.length);
|
||||
setTransactions(storedTransactions);
|
||||
console.log('로컬 스토리지에서 트랜잭션 로드:', storedTransactions?.length || 0);
|
||||
setTransactions(storedTransactions || []);
|
||||
} catch (error) {
|
||||
console.error('트랜잭션 로드 중 오류 발생:', error);
|
||||
// 오류 발생 시 빈 배열로 초기화
|
||||
@@ -27,41 +27,57 @@ export const useTransactionState = () => {
|
||||
|
||||
// 트랜잭션 변경 시 로컬 스토리지에 저장
|
||||
useEffect(() => {
|
||||
if (transactions.length > 0) {
|
||||
console.log('트랜잭션 저장 중:', transactions.length);
|
||||
saveTransactionsToStorage(transactions);
|
||||
try {
|
||||
if (transactions && transactions.length > 0) {
|
||||
console.log('트랜잭션 저장 중:', transactions.length);
|
||||
saveTransactionsToStorage(transactions);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('트랜잭션 저장 중 오류 발생:', error);
|
||||
}
|
||||
}, [transactions]);
|
||||
|
||||
// 트랜잭션 추가
|
||||
const addTransaction = (transaction: Transaction) => {
|
||||
const newTransaction = {
|
||||
...transaction,
|
||||
id: transaction.id || uuidv4(),
|
||||
localTimestamp: new Date().toISOString()
|
||||
};
|
||||
setTransactions(prevTransactions => [...prevTransactions, newTransaction]);
|
||||
console.log('트랜잭션 추가됨:', newTransaction);
|
||||
try {
|
||||
const newTransaction = {
|
||||
...transaction,
|
||||
id: transaction.id || uuidv4(),
|
||||
localTimestamp: new Date().toISOString()
|
||||
};
|
||||
setTransactions(prevTransactions => [...(prevTransactions || []), newTransaction]);
|
||||
console.log('트랜잭션 추가됨:', newTransaction);
|
||||
} catch (error) {
|
||||
console.error('트랜잭션 추가 중 오류 발생:', error);
|
||||
}
|
||||
};
|
||||
|
||||
// 트랜잭션 업데이트
|
||||
const updateTransaction = (updatedTransaction: Transaction) => {
|
||||
setTransactions(prevTransactions =>
|
||||
prevTransactions.map(transaction =>
|
||||
transaction.id === updatedTransaction.id
|
||||
? { ...updatedTransaction, localTimestamp: new Date().toISOString() }
|
||||
: transaction
|
||||
)
|
||||
);
|
||||
console.log('트랜잭션 업데이트됨:', updatedTransaction.id);
|
||||
try {
|
||||
setTransactions(prevTransactions =>
|
||||
(prevTransactions || []).map(transaction =>
|
||||
transaction.id === updatedTransaction.id
|
||||
? { ...updatedTransaction, localTimestamp: new Date().toISOString() }
|
||||
: transaction
|
||||
)
|
||||
);
|
||||
console.log('트랜잭션 업데이트됨:', updatedTransaction.id);
|
||||
} catch (error) {
|
||||
console.error('트랜잭션 업데이트 중 오류 발생:', error);
|
||||
}
|
||||
};
|
||||
|
||||
// 트랜잭션 삭제
|
||||
const deleteTransaction = (id: string) => {
|
||||
setTransactions(prevTransactions =>
|
||||
prevTransactions.filter(transaction => transaction.id !== id)
|
||||
);
|
||||
console.log('트랜잭션 삭제됨:', id);
|
||||
try {
|
||||
setTransactions(prevTransactions =>
|
||||
(prevTransactions || []).filter(transaction => transaction.id !== id)
|
||||
);
|
||||
console.log('트랜잭션 삭제됨:', id);
|
||||
} catch (error) {
|
||||
console.error('트랜잭션 삭제 중 오류 발생:', error);
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user