Skip to content

Latest commit

 

History

History
42 lines (29 loc) · 1.04 KB

README.md

File metadata and controls

42 lines (29 loc) · 1.04 KB

react-safetynet

react-safetynet provides a simple way to encapsulate errors, preventing them from crashing your app completely. Upon receiving an error from one of its children, the component will swap it's contents with an explanation of what went wrong.

Usage

JavaScript

import SafetyNet from 'react-safetynet';

class App extends React.Component {
   render() {
      return (
         <div>
            <h1>SafetyNet Example</h1>

            <SafetyNet>
               {/* The following component throws an error in its render() method */}
               <SuspiciousComponent></SuspiciousComponent>
            </SafetyNet>
         </div>
      );
   }
}

Result

Result

API

The following may be passed as props.

errorHandler

  • Type: (error: Error, errorInfo: React.ErrorInfo) => void

Will be called when an error is caught by the SafetyNet instance. For complete documenation of error and errorInfo, see the React docs.