- Hands-On Design Patterns with React Native
- Mateusz Grzesiukiewicz
- 264字
- 2021-08-13 15:13:02
When to use error boundaries
ErrorBoundary is a great pattern for sure. It takes the try-catch concept into declarative JSX. The first time I saw it, I immediately came up with the idea to wrap the whole application into a boundary. This is fine, but it is not the only use case.
Consider the following use cases for error boundaries:
- Widgets: Given some incorrect data, your widget may run into problems. If, in the worst case scenario, it cannot handle the data, it may throw an error. You will want the rest of the app to be usable, given that this widget is not crucial for the rest of the application. Your analytics code should collect the error and save at least a stack trace so that the developers can fix it.
- Modals: Preserve the rest of the application from the faulty modal. These are usually meant to display some data and short messages. You do not want a modal to blow up your application. Such errors should be considered very rare, but better safe than sorry.
- Boundaries on feature containers: Let's say that your app is divided into major features that are represented by container components. For example, let's take a messaging app such as Facebook Messenger. You may add error boundaries to the sidebar, my story bar, footer, start new message button, and messages history list view. This will ensure that, if one feature breaks, the others have a chance to still work properly.
Now we know about all of the pros, let's discuss the cons ones: Mixins.
推薦閱讀
- WildFly:New Features
- PyTorch自動駕駛視覺感知算法實戰
- Offer來了:Java面試核心知識點精講(原理篇)
- Developing Middleware in Java EE 8
- 趣學Python算法100例
- Mastering Kotlin
- C語言程序設計
- Windows Server 2016 Automation with PowerShell Cookbook(Second Edition)
- 單片機C語言程序設計實訓100例
- Hands-On Nuxt.js Web Development
- Android應用開發深入學習實錄
- IPython Interactive Computing and Visualization Cookbook
- ASP.NET開發寶典
- C語言程序設計教程
- 深入大型數據集:并行與分布化Python代碼