shubham choudhary
shubham choudhary

Reputation: 3110

What is the best way to do Error Handling in React Native App.

There are a few approaches which people use.

1: One way is to use hoc's(Higher Order components) with global handlers using interceptors in axios.

2: Another way is to create an action creator for error and store errors in Reducer store, Fire the one action creator which is responsible for catching errors from the catch block. Currently, in most places, we have unhandled promise rejection.

Please let me know if there is any other approach to error handling, we want to show different error messages to the user for different errors. Example: Error can occur while accepting the order.

Upvotes: 4

Views: 14453

Answers (1)

Bhojendra Rauniyar
Bhojendra Rauniyar

Reputation: 85545

You can use error boundary. Wrap your root app inside ErrorBoundary, then you'll be able to catch error in any of the components:

<ErrorBoundary>
  <App />
</ErrorBoundary>

Here's a demo from the docs: Catching errors with error boundary

Upvotes: 4

Related Questions