Fixed initial errors

This commit is contained in:
2024-10-18 12:39:54 -05:00
parent 3eeffb789f
commit cc8e0c623c
10 changed files with 78 additions and 30 deletions

View File

@ -1,9 +1,10 @@
import React, { useState, useEffect, useRef } from 'react';
import React, { useState, useEffect, useRef, ErrorInfo } from 'react';
import { Alert, Platform } from 'react-native';
import * as Device from 'expo-device';
import * as Notifications from 'expo-notifications';
import Constants from 'expo-constants';
import type { NotificationMessage } from '@/constants/Types';
import { ThemedText } from '@/components/theme/Theme';
Notifications.setNotificationHandler({
handleNotification: async () => ({
@ -114,5 +115,33 @@ export const PushNotificationManager = ({children}: {children: React.ReactNode})
Notifications.removeNotificationSubscription(responseListener.current);
};
}, []);
return ( <> {children} </> );
//return ( <> {children} </> );
return (
<ErrorBoundary>
{children}
</ErrorBoundary>
);
};
class ErrorBoundary extends React.Component<{children: React.ReactNode}, {hasError: boolean}> {
constructor(props: {children: React.ReactNode}) {
super(props);
this.state = { hasError: false };
}
static getDerivedStateFromError(_: Error) {
return { hasError: true };
}
componentDidCatch(error: Error, errorInfo: ErrorInfo) {
console.log('Error caught by ErrorBoundary:', error, errorInfo);
}
render() {
if (this.state.hasError) {
return <ThemedText>Something went wrong.</ThemedText>;
}
return this.props.children;
}
}