Skip to main content

Logging Errors

You can log the error by providing an onError property to the component.

Import the ErrorBoundary component:

import ErrorBoundary from 'react-native-error-boundary'

Then, wrap it around any component that could throw an error using the onError callback function:

const errorHandler = (error: Error, stackTrace: string) => {
/* Log the error to an error reporting service */
}

const App = () => (
<ErrorBoundary onError={errorHandler}>
<ChildrenThatCouldThrowEror />
</ErrorBoundary>
)

This onError function can be useful to log the errors that happen in your application to an error monitoring service such as: Bugsnag, Sentry 🐛