A React Native app for the ultimate thinking partner.
1import { useCallback } from 'react';
2import { Alert } from 'react-native';
3
4/**
5 * Centralized error handling hook
6 */
7export function useErrorHandler() {
8 const showError = useCallback((error: Error | string, title: string = 'Error') => {
9 const message = typeof error === 'string' ? error : error.message;
10 console.error(`[Error Handler] ${title}:`, error);
11 Alert.alert(title, message);
12 }, []);
13
14 const showConfirm = useCallback(
15 (title: string, message: string, onConfirm: () => void, onCancel?: () => void) => {
16 Alert.alert(title, message, [
17 { text: 'Cancel', style: 'cancel', onPress: onCancel },
18 { text: 'OK', onPress: onConfirm },
19 ]);
20 },
21 []
22 );
23
24 return {
25 showError,
26 showConfirm,
27 };
28}