diff --git a/hooks/useTransactions.ts b/hooks/useTransactions.ts new file mode 100644 index 0000000..54760be --- /dev/null +++ b/hooks/useTransactions.ts @@ -0,0 +1,34 @@ +import { useState, useEffect } from 'react'; +import AsyncStorage from '@react-native-async-storage/async-storage'; +import { Transaction } from '../types'; + +const STORAGE_KEY = '@finance_transactions'; + +export const useTransactions = () => { + const [transactions, setTransactions] = useState([]); + const [loading, setLoading] = useState(true); + + const loadTransactions = async () => { + try { + setLoading(true); + const stored = await AsyncStorage.getItem(STORAGE_KEY); + if (stored) { + setTransactions(JSON.parse(stored)); + } + } catch (error) { + console.error('Error loading transactions:', error); + } finally { + setLoading(false); + } + }; + + useEffect(() => { + loadTransactions(); + }, []); + + return { + transactions, + loading, + refresh: loadTransactions, + }; +}; \ No newline at end of file