GithubHelp home page GithubHelp logo

skiano / react-safe-render Goto Github PK

View Code? Open in Web Editor NEW
48.0 7.0 9.0 20 KB

Helper to make sure your react components do not kill your entire Application when they fail to render

License: MIT License

JavaScript 100.00%

react-safe-render's Introduction

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

react-safe-render's People

Contributors

skiano avatar vinnymac avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-safe-render's Issues

Error report has no state

I noticed that react-safe-render exposes some parts of the component such as displayName, props, and the lifecycle method that threw the error. Is their a reason the state isn't exposed as well? Why not expose the component itself in the report?

An additional benefit other than your entire tree not getting locked up is that you can now reveal exactly which components in your app are failing and what state they were in when they failed. It would be useful to have as much information as possible. Thoughts?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.