Meet npm Pro: unlimited public & private packages + package-based permissions.Learn more »

react-trycatch

1.0.1 • Public • Published

react-trycatch

npm Travis branch npm

Implement React v16 ErrorBoundary with HOC pattern

Installation

npm install --save react-trycatch

Usage

1. Default Usage

import React from 'react';
import TryCatch from 'react-trycatch';
 
class MyComponent extends React.Component {
 
    render() {
        throw new Error('Error!!!');
        return (
            <div>MyComponent</div>
        );
    }
}
 
export default TryCatch()(MyComponent);

2. With Options

import React from 'react';
import TryCatch from 'react-trycatch';
 
class MyComponent extends React.Component {
 
    render() {
        throw new Error('Error!!!');
        return (
            <div>MyComponent</div>
        );
    }
}
 
export default TryCatch({
    replacement: (<div>Replacement on error</div>),
    onError: (error, info) => {
        // catch
    }
})(MyComponent);

Install

npm i react-trycatch

DownloadsWeekly Downloads

1

Version

1.0.1

License

MIT

Unpacked Size

2.57 kB

Total Files

2

Last publish

Collaborators

  • avatar