UNPKG

rn-dynamic-ui-render

Version:
34 lines (27 loc) 737 B
import { Component } from "react"; import { View, Text } from "react-native"; class ErrorBoundary extends Component { constructor(props) { super(props); this.state = { hasError: false }; } static getDerivedStateFromError(error) { return { hasError: true }; } componentDidCatch(error, errorInfo) { console.error("ErrorBoundary caught an error", error, errorInfo); } render() { if (this.state.hasError) { return ( <View style={{ flex: 1, justifyContent: "center", alignItems: "center" }} > <Text>Something went wrong.</Text> </View> ); } return this.props.children; } } export default ErrorBoundary;