dugong
dugong

Reputation: 4411

How to log errors in browser (error view) instead of blank screen in React

I have a React application which is not created with create-react-app. I would like to add a error handling functionality but I have no idea how:

When there is an error, instead of getting a blank page and errors in console, in development, how do I enable this functionality in a React application where it shows the error stack in the browser?

Do I have to write the code for it or there is a react configuration that I can just enable or should I use a library to achieve this?

React application, error stack in browser

EDIT:

Above image is what I want to see as an error report in my browser when there is an error. It is not an error I am trying to solve.

Upvotes: 3

Views: 2360

Answers (1)

Viswanath Lekshmanan
Viswanath Lekshmanan

Reputation: 10083

Try Error Boundaries . Add those in your Root Level to catch all errors inside that.

Upvotes: 1

Related Questions