feat: add deleteTransaction function

- Add deleteTransaction callback to hook
- Use filter to remove by id
- Save to AsyncStorage after delete
This commit is contained in:
Dita Aji Pratama 2026-04-18 12:21:53 +07:00
parent 2b532c7472
commit 8d3c4796ea

View File

@ -34,10 +34,19 @@ export const useTransactions = () => {
}); });
}, []); }, []);
const deleteTransaction = useCallback((id: string) => {
setTransactions((prev) => {
const updated = prev.filter((t) => t.id !== id);
AsyncStorage.setItem(STORAGE_KEY, JSON.stringify(updated));
return updated;
});
}, []);
return { return {
transactions, transactions,
loading, loading,
addTransaction, addTransaction,
deleteTransaction,
refresh: loadTransactions, refresh: loadTransactions,
}; };
}; };