react-safe-render

2.0.0 • Public • Published

React Safe Render Build Status NPM version

Helper to make sure your react components do not kill your entire application when their lifecylce methods fail.

Usage

Before any other components are created

 
var React = require('react');
 
require('react-safe-render')(React, {
  errorHandler: function (errReport) {
    
    // if a component fails you can handle the failure however you want
    
    errReport.displayName // name of component that failed
    errReport.props // the props that the component recieved
    errReport.method // name of method that failed (ie: componentWillMount)
    errReport.arguments // arguments for the method that failed (if there were any)
    errReport.error // the original error object
  }
});
 

Note on es2015

At the moment this only works for components made via React.createClass(). It will not catch errors if you use the Component class directly.

Disable for a single component

If you want to disable the error handler for a component, you can use a static property

React.createClass({
  statics: {
    bubbleErrors: true
  },
 
  // ...
 
});
 

License

MIT

Package Sidebar

Install

npm i react-safe-render

Weekly Downloads

218

Version

2.0.0

License

MIT

Last publish

Collaborators

  • skiano