Helper to make sure your react components do not kill your entire application when their lifecylce methods fail.
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
}
});
At the moment this only works for components made via React.createClass(). It will not catch errors if you use the Component class directly.
If you want to disable the error handler for a component, you can use a static property
React.createClass({
statics: {
bubbleErrors: true
},
// ...
});