React Native error handler for unhandled exception
npm install --save rn-global-error-handler
Extend your top level component from SafeComponent. This shows a popup whenever an unhandled exception airses and doesn't kill the app.
import { Text } from "react-native";
import SafeComponent from "rn-global-error-handler";
class App extends SafeComponent {
constructor(){
super();
}
render(){
return <Text>Cool App!</Text>
}
}
export default App;
Compopse your top level component with "safe" function. This shows a popup whenever an unhandled exception airses and doesn't kill the app.
import { Text } from "react-native";
import {safe} from "rn-global-error-handler";
class App extends SafeComponent {
constructor(){
super();
}
render(){
return <Text>Cool App!</Text>
}
}
export default safe(App);
const App = () => {
return <Text>Cool App!</Text>
}
export default safe(App);
const App = () => {
return <Text>Cool App!</Text>
}
export default safe(App,true);
function customErrHandler() {
// log error message
alert("This is a custom error handler");
}
const App = () => {
return <Text>Cool App!</Text>
}
export default safe(App,true,customErrHandler);
MIT © mujib517