kentcdodds / ama

Ask me anything!
https://github.com/kentcdodds/ama/issues?q=is%3Aissue+is%3Aclosed
685 stars 75 forks source link

Using Error boundry in react app #849

Closed slim-hmidi closed 3 years ago

slim-hmidi commented 3 years ago

Hi, I saw once a video on youtube that you fix an issue on react-error-boundry and I see on your project bookshelf that you use it inside authenticated-app.js. I'm used to add the ErrorBoundry component code from the react documentation and wrap the main component of my app with it. What do you think about that? or do you recommend to add it around some specific components or any components that you use in the app or the container components in the project?

kentcdodds commented 3 years ago

Hi @slim-hmidi,

Think of ErrorBoundaries like you think of try/catch. If you put a single try/catch around your whole app, how useful is that with regard to the usefulness of the error message and recovery? Not very. But if you put try/catches around specific areas of your app then you can provide much more useful error messages and recover from errors much more easily.

I talk about this in https://EpicReact.Dev :) Good luck!

slim-hmidi commented 3 years ago

@kentcdodds thanks a lot for this answer. The idea of try/catch makes things more clear for me. Thanks for youyr time and advice ;)