https://github.com/kossnocorp/react-guard
🦄 React Guard automagically catches exceptions from React components, extracts useful debug information and prevents White Screen of Death 👻
https://github.com/kossnocorp/react-guard
exception-handler exceptions javascript react
Last synced: about 2 months ago
JSON representation
🦄 React Guard automagically catches exceptions from React components, extracts useful debug information and prevents White Screen of Death 👻
- Host: GitHub
- URL: https://github.com/kossnocorp/react-guard
- Owner: kossnocorp
- License: other
- Created: 2014-12-08T15:21:44.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2022-08-30T04:15:56.000Z (almost 3 years ago)
- Last Synced: 2025-05-01T20:01:53.787Z (about 2 months ago)
- Topics: exception-handler, exceptions, javascript, react
- Language: JavaScript
- Homepage:
- Size: 84 KB
- Stars: 96
- Watchers: 46
- Forks: 6
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
# React Guard
React Guard helps to prevent White Screen of Death,
improves user expirience and assists in the bug hunt.It patches React, so it wraps every render function (including
function components) intro try-catch block.If an exception occurs during the rendering, it calls specified guard function.
The guard function gets the exception object and extra information such as
the component `props`, `state` and `displayName`.## Installation
```
npm install react-guard --save
```or
```
yarn add react-guard
```## Usage
```javascript
var React = require('react')
var reactGuard = require('react-guard')// Catch and process component render exceptions.
reactGuard(React, function (err, componentInfo) {
// Print stacktrace to the console
console && console.error && console.error(err.stack)// Notify Sentry (replace with your service of choice)
Raven.captureException(err, {
extra: {
props: componentInfo.props,
state: componentInfo.state,
displayName: componentInfo.displayName
}
})// Replace failed component with "Failed to render".
// Use `return null` to render nothing.
returnFailed to render
})
```## License
[MIT © Sasha Koss](https://kossnocorp.mit-license.org/)