вот демонстрация: https://snack.expo.io/@carloscuesta / response-native-error-граница
вы можете использовать response-native-error-граница
yarn add react-native-error-boundary
это не обрабатывает собственные ошибки, но обрабатывает все ошибки уровня js. вы можете комбинировать использование этого пакета с обработчиком исключений response-native-exception.
import * as React from 'react';
import { Button, Text, View, StyleSheet } from 'react-native';
import Constants from 'expo-constants';
import ErrorBoundary from 'react-native-error-boundary';
import ComponentWithError from './ComponentWithError'
const App = () => {
const [isErrorComponentVisible, setIsErrorComponentVisible] = React.useState(false)
return (
<ErrorBoundary>
<View style={styles.container}>
<Text style={styles.icon}>?</Text>
<Text style={styles.title}>
react-native-error-boundary
</Text>
<Text style={styles.text}>
Click on the following button to render a component that will throw an error.
</Text>
<Button title='Throw error' onPress={() => setIsErrorComponentVisible(true)} />
{isErrorComponentVisible && <ComponentWithError />}
</View>
</ErrorBoundary>
)
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
paddingTop: Constants.statusBarHeight,
backgroundColor: '#ecf0f1',
padding: 8,
textAlign: 'center',
},
title: {
fontSize: 18,
fontWeight: 'bold',
textAlign: 'center',
},
icon: {
fontSize: 48
},
text: {
marginVertical: 16
}
});
export default App