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;
