Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Spencer Carli
Spencer Carli

Posted on • Originally published atreactnativeschool.com

     

How to Detect Crashes in a React Native App

Originally published atwww.reactnativeschool.com/how-to-detect-crashes-in-a-react-native-app. If you're interested in learning more about React Native visit the site for 75+ tutorials!

In this lesson we learn how to handle errors in production. I would suggest checking outreact-native-exception-handler as a way to get started with capture errors in all runtimes of React Native.

If you're ready to go one step further Ihighly suggest taking a look atInstabug.Instabug provides a platform and tooling to capture and analyze errors in your React Native app, in addition to other things (like capturing user feedback).

They've gratuitously sponsored the production of an entire class about debugging React Native apps so everyone can access it. You can access the course,How to Debug React Native Apps in Development and Production here on React Native School.

Commands and code from the lesson:

Terminal

yarn add react-native-exception-handlerreact-nativelinkreact-native-exception-handler

App.js

importReactfrom'react';import{View,Button}from'react-native';import{setJSExceptionHandler,setNativeExceptionHandler,}from'react-native-exception-handler';consthandleError=(error,isFatal)=>{// fetchconsole.log(error,isFatal);alert(error.name);};setJSExceptionHandler((error,isFatal)=>{console.log('caught global error');handleError(error,isFatal);},true);setNativeExceptionHandler(errorString=>{// do the things});exportdefaultclassAppextendsReact.Component{state={number:0,};makeRequest=()=>{fetch('asdf').then(res=>res.json()).then(res=>{alert(res);}).catch(error=>{handleError(error,false);});};badStateChange=()=>{this.setState(state=>({number:state.data.number+1,}));};render(){return(<Viewstyle={{flex:1,backgroundColor:'#fff',alignItems:'center',justifyContent:'center',}}><Buttontitle="Make an invalid request"onPress={this.makeRequest}/><Buttontitle="Bad state change"onPress={this.badStateChange}/></View>);}}

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Student. Teacher. Firefighter. Pizza fiend. I teach others while teaching myself, typically with React Native.
  • Location
    Nashville, TN
  • Work
    Developer/Teacher
  • Joined

More fromSpencer Carli

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp