24 lines
489 B
JavaScript
24 lines
489 B
JavaScript
import React, { Component } from "react";
|
|
import { Text } from "react-native";
|
|
|
|
class ErrorBoundary extends Component {
|
|
state = { hasError: false };
|
|
|
|
static getDerivedStateFromError() {
|
|
return { hasError: true };
|
|
}
|
|
|
|
componentDidCatch(error, info) {
|
|
console.error("Error caught by Error Boundary:", error);
|
|
}
|
|
|
|
render() {
|
|
if (this.state.hasError) {
|
|
return <Text>Error Occurred!</Text>;
|
|
}
|
|
return this.props.children;
|
|
}
|
|
}
|
|
|
|
export default ErrorBoundary;
|