1 | 'use strict';
|
2 |
|
3 | exports.__esModule = true;
|
4 | exports.default = undefined;
|
5 |
|
6 | var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
|
7 |
|
8 | var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
|
9 |
|
10 | var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');
|
11 |
|
12 | var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
|
13 |
|
14 | var _inherits2 = require('babel-runtime/helpers/inherits');
|
15 |
|
16 | var _inherits3 = _interopRequireDefault(_inherits2);
|
17 |
|
18 | var _class, _temp;
|
19 |
|
20 | var _react = require('react');
|
21 |
|
22 | var _react2 = _interopRequireDefault(_react);
|
23 |
|
24 | var _propTypes = require('prop-types');
|
25 |
|
26 | var _propTypes2 = _interopRequireDefault(_propTypes);
|
27 |
|
28 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
29 |
|
30 | DefaultUI.propTypes = {
|
31 | error: _propTypes2.default.object,
|
32 | errorInfo: _propTypes2.default.object
|
33 | };
|
34 |
|
35 | function DefaultUI() {
|
36 | return '';
|
37 | }
|
38 |
|
39 | var ErrorBoundary = (_temp = _class = function (_React$Component) {
|
40 | (0, _inherits3.default)(ErrorBoundary, _React$Component);
|
41 |
|
42 | function ErrorBoundary(props) {
|
43 | (0, _classCallCheck3.default)(this, ErrorBoundary);
|
44 |
|
45 | var _this = (0, _possibleConstructorReturn3.default)(this, _React$Component.call(this, props));
|
46 |
|
47 | _this.state = { error: null, errorInfo: null };
|
48 | return _this;
|
49 | }
|
50 |
|
51 | ErrorBoundary.prototype.componentDidCatch = function componentDidCatch(error, errorInfo) {
|
52 | this.setState({
|
53 | error: error,
|
54 | errorInfo: errorInfo
|
55 | });
|
56 |
|
57 | var afterCatch = this.props.afterCatch;
|
58 |
|
59 |
|
60 | if ('afterCatch' in this.props && typeof afterCatch === 'function') {
|
61 | this.props.afterCatch(error, errorInfo);
|
62 | }
|
63 | };
|
64 |
|
65 | ErrorBoundary.prototype.render = function render() {
|
66 | var _props$fallbackUI = this.props.fallbackUI,
|
67 | FallbackUI = _props$fallbackUI === undefined ? DefaultUI : _props$fallbackUI;
|
68 |
|
69 |
|
70 | if (this.state.errorInfo) {
|
71 | return _react2.default.createElement(FallbackUI, {
|
72 | error: this.state.error,
|
73 | errorInfo: this.state.errorInfo
|
74 | });
|
75 | }
|
76 |
|
77 | return this.props.children;
|
78 | };
|
79 |
|
80 | return ErrorBoundary;
|
81 | }(_react2.default.Component), _class.propTypes = {
|
82 | children: _propTypes2.default.element,
|
83 | |
84 |
|
85 |
|
86 |
|
87 |
|
88 | afterCatch: _propTypes2.default.func,
|
89 | |
90 |
|
91 |
|
92 |
|
93 |
|
94 |
|
95 | fallbackUI: _propTypes2.default.func
|
96 | }, _temp);
|
97 | ErrorBoundary.displayName = 'ErrorBoundary';
|
98 | exports.default = ErrorBoundary;
|
99 | module.exports = exports['default']; |
\ | No newline at end of file |