react-error-boundary
Advanced tools
Comparing version 3.1.3 to 3.1.4
@@ -49,8 +49,6 @@ import * as React from 'react'; | ||
state: ErrorBoundaryState; | ||
updatedWithError: boolean; | ||
resetErrorBoundary: (...args: Array<unknown>) => void; | ||
reset(): void; | ||
componentDidCatch(error: Error, info: React.ErrorInfo): void; | ||
componentDidMount(): void; | ||
componentDidUpdate(prevProps: ErrorBoundaryProps): void; | ||
componentDidUpdate(prevProps: ErrorBoundaryProps, prevState: ErrorBoundaryState): void; | ||
render(): React.ReactNode; | ||
@@ -57,0 +55,0 @@ } |
@@ -19,5 +19,3 @@ 'use strict'; | ||
enumerable: true, | ||
get: function () { | ||
return e[k]; | ||
} | ||
get: function () { return e[k]; } | ||
}); | ||
@@ -27,3 +25,3 @@ } | ||
} | ||
n['default'] = e; | ||
n["default"] = e; | ||
return Object.freeze(n); | ||
@@ -54,3 +52,3 @@ } | ||
var ErrorBoundary = /*#__PURE__*/function (_React$Component) { | ||
_inheritsLoose__default['default'](ErrorBoundary, _React$Component); | ||
_inheritsLoose__default["default"](ErrorBoundary, _React$Component); | ||
@@ -66,3 +64,2 @@ function ErrorBoundary() { | ||
_this.state = initialState; | ||
_this.updatedWithError = false; | ||
@@ -93,3 +90,2 @@ _this.resetErrorBoundary = function () { | ||
_proto.reset = function reset() { | ||
this.updatedWithError = false; | ||
this.setState(initialState); | ||
@@ -104,12 +100,4 @@ }; | ||
_proto.componentDidMount = function componentDidMount() { | ||
_proto.componentDidUpdate = function componentDidUpdate(prevProps, prevState) { | ||
var error = this.state.error; | ||
if (error !== null) { | ||
this.updatedWithError = true; | ||
} | ||
}; | ||
_proto.componentDidUpdate = function componentDidUpdate(prevProps) { | ||
var error = this.state.error; | ||
var resetKeys = this.props.resetKeys; // There's an edge case where if the thing that triggered the error | ||
@@ -122,8 +110,3 @@ // happens to *also* be in the resetKeys array, we'd end up resetting | ||
if (error !== null && !this.updatedWithError) { | ||
this.updatedWithError = true; | ||
return; | ||
} | ||
if (error !== null && changedArray(prevProps.resetKeys, resetKeys)) { | ||
if (error !== null && prevState.error !== null && changedArray(prevProps.resetKeys, resetKeys)) { | ||
var _this$props$onResetKe, _this$props3; | ||
@@ -188,2 +171,3 @@ | ||
eslint | ||
@typescript-eslint/sort-type-union-intersection-members: "off", | ||
@typescript-eslint/no-throw-literal: "off", | ||
@@ -190,0 +174,0 @@ @typescript-eslint/prefer-nullish-coalescing: "off" |
@@ -34,3 +34,2 @@ import _inheritsLoose from '@babel/runtime/helpers/esm/inheritsLoose'; | ||
_this.state = initialState; | ||
_this.updatedWithError = false; | ||
@@ -61,3 +60,2 @@ _this.resetErrorBoundary = function () { | ||
_proto.reset = function reset() { | ||
this.updatedWithError = false; | ||
this.setState(initialState); | ||
@@ -72,12 +70,4 @@ }; | ||
_proto.componentDidMount = function componentDidMount() { | ||
_proto.componentDidUpdate = function componentDidUpdate(prevProps, prevState) { | ||
var error = this.state.error; | ||
if (error !== null) { | ||
this.updatedWithError = true; | ||
} | ||
}; | ||
_proto.componentDidUpdate = function componentDidUpdate(prevProps) { | ||
var error = this.state.error; | ||
var resetKeys = this.props.resetKeys; // There's an edge case where if the thing that triggered the error | ||
@@ -90,8 +80,3 @@ // happens to *also* be in the resetKeys array, we'd end up resetting | ||
if (error !== null && !this.updatedWithError) { | ||
this.updatedWithError = true; | ||
return; | ||
} | ||
if (error !== null && changedArray(prevProps.resetKeys, resetKeys)) { | ||
if (error !== null && prevState.error !== null && changedArray(prevProps.resetKeys, resetKeys)) { | ||
var _this$props$onResetKe, _this$props3; | ||
@@ -156,2 +141,3 @@ | ||
eslint | ||
@typescript-eslint/sort-type-union-intersection-members: "off", | ||
@typescript-eslint/no-throw-literal: "off", | ||
@@ -158,0 +144,0 @@ @typescript-eslint/prefer-nullish-coalescing: "off" |
@@ -5,3 +5,3 @@ (function (global, factory) { | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ReactErrorBoundary = {}, global.React)); | ||
}(this, (function (exports, React) { 'use strict'; | ||
})(this, (function (exports, React) { 'use strict'; | ||
@@ -17,5 +17,3 @@ function _interopNamespace(e) { | ||
enumerable: true, | ||
get: function () { | ||
return e[k]; | ||
} | ||
get: function () { return e[k]; } | ||
}); | ||
@@ -25,3 +23,3 @@ } | ||
} | ||
n['default'] = e; | ||
n["default"] = e; | ||
return Object.freeze(n); | ||
@@ -77,3 +75,2 @@ } | ||
_this.state = initialState; | ||
_this.updatedWithError = false; | ||
@@ -104,3 +101,2 @@ _this.resetErrorBoundary = function () { | ||
_proto.reset = function reset() { | ||
this.updatedWithError = false; | ||
this.setState(initialState); | ||
@@ -115,12 +111,4 @@ }; | ||
_proto.componentDidMount = function componentDidMount() { | ||
_proto.componentDidUpdate = function componentDidUpdate(prevProps, prevState) { | ||
var error = this.state.error; | ||
if (error !== null) { | ||
this.updatedWithError = true; | ||
} | ||
}; | ||
_proto.componentDidUpdate = function componentDidUpdate(prevProps) { | ||
var error = this.state.error; | ||
var resetKeys = this.props.resetKeys; // There's an edge case where if the thing that triggered the error | ||
@@ -133,8 +121,3 @@ // happens to *also* be in the resetKeys array, we'd end up resetting | ||
if (error !== null && !this.updatedWithError) { | ||
this.updatedWithError = true; | ||
return; | ||
} | ||
if (error !== null && changedArray(prevProps.resetKeys, resetKeys)) { | ||
if (error !== null && prevState.error !== null && changedArray(prevProps.resetKeys, resetKeys)) { | ||
var _this$props$onResetKe, _this$props3; | ||
@@ -199,2 +182,3 @@ | ||
eslint | ||
@typescript-eslint/sort-type-union-intersection-members: "off", | ||
@typescript-eslint/no-throw-literal: "off", | ||
@@ -210,3 +194,3 @@ @typescript-eslint/prefer-nullish-coalescing: "off" | ||
}))); | ||
})); | ||
//# sourceMappingURL=react-error-boundary.umd.js.map |
@@ -1,2 +0,2 @@ | ||
!function(r,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],e):e((r="undefined"!=typeof globalThis?globalThis:r||self).ReactErrorBoundary={},r.React)}(this,(function(r,e){"use strict";function t(r){if(r&&r.__esModule)return r;var e=Object.create(null);return r&&Object.keys(r).forEach((function(t){if("default"!==t){var n=Object.getOwnPropertyDescriptor(r,t);Object.defineProperty(e,t,n.get?n:{enumerable:!0,get:function(){return r[t]}})}})),e.default=r,Object.freeze(e)}var n=t(e);function o(r,e){return(o=Object.setPrototypeOf||function(r,e){return r.__proto__=e,r})(r,e)}var a={error:null},i=function(r){var e,t;function i(){for(var e,t=arguments.length,n=new Array(t),o=0;o<t;o++)n[o]=arguments[o];return(e=r.call.apply(r,[this].concat(n))||this).state=a,e.updatedWithError=!1,e.resetErrorBoundary=function(){for(var r,t=arguments.length,n=new Array(t),o=0;o<t;o++)n[o]=arguments[o];null==e.props.onReset||(r=e.props).onReset.apply(r,n),e.reset()},e}t=r,(e=i).prototype=Object.create(t.prototype),e.prototype.constructor=e,o(e,t),i.getDerivedStateFromError=function(r){return{error:r}};var u=i.prototype;return u.reset=function(){this.updatedWithError=!1,this.setState(a)},u.componentDidCatch=function(r,e){var t,n;null==(t=(n=this.props).onError)||t.call(n,r,e)},u.componentDidMount=function(){null!==this.state.error&&(this.updatedWithError=!0)},u.componentDidUpdate=function(r){var e,t,n,o,a=this.state.error,i=this.props.resetKeys;null===a||this.updatedWithError?null!==a&&(void 0===(n=r.resetKeys)&&(n=[]),void 0===(o=i)&&(o=[]),n.length!==o.length||n.some((function(r,e){return!Object.is(r,o[e])})))&&(null==(e=(t=this.props).onResetKeysChange)||e.call(t,r.resetKeys,i),this.reset()):this.updatedWithError=!0},u.render=function(){var r=this.state.error,e=this.props,t=e.fallbackRender,o=e.FallbackComponent,a=e.fallback;if(null!==r){var i={error:r,resetErrorBoundary:this.resetErrorBoundary};if(n.isValidElement(a))return a;if("function"==typeof t)return t(i);if(o)return n.createElement(o,i);throw new Error("react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop")}return this.props.children},i}(n.Component);r.ErrorBoundary=i,r.useErrorHandler=function(r){var e=n.useState(null),t=e[0],o=e[1];if(null!=r)throw r;if(null!=t)throw t;return o},r.withErrorBoundary=function(r,e){var t=function(t){return n.createElement(i,e,n.createElement(r,t))},o=r.displayName||r.name||"Unknown";return t.displayName="withErrorBoundary("+o+")",t},Object.defineProperty(r,"__esModule",{value:!0})})); | ||
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],r):r((e="undefined"!=typeof globalThis?globalThis:e||self).ReactErrorBoundary={},e.React)}(this,(function(e,r){"use strict";function t(e){if(e&&e.__esModule)return e;var r=Object.create(null);return e&&Object.keys(e).forEach((function(t){if("default"!==t){var n=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,n.get?n:{enumerable:!0,get:function(){return e[t]}})}})),r.default=e,Object.freeze(r)}var n=t(r);function o(e,r){return o=Object.setPrototypeOf||function(e,r){return e.__proto__=r,e},o(e,r)}var a={error:null},u=function(e){var r,t;function u(){for(var r,t=arguments.length,n=new Array(t),o=0;o<t;o++)n[o]=arguments[o];return(r=e.call.apply(e,[this].concat(n))||this).state=a,r.resetErrorBoundary=function(){for(var e,t=arguments.length,n=new Array(t),o=0;o<t;o++)n[o]=arguments[o];null==r.props.onReset||(e=r.props).onReset.apply(e,n),r.reset()},r}t=e,(r=u).prototype=Object.create(t.prototype),r.prototype.constructor=r,o(r,t),u.getDerivedStateFromError=function(e){return{error:e}};var i=u.prototype;return i.reset=function(){this.setState(a)},i.componentDidCatch=function(e,r){var t,n;null==(t=(n=this.props).onError)||t.call(n,e,r)},i.componentDidUpdate=function(e,r){var t,n,o,a,u=this.state.error,i=this.props.resetKeys;null!==u&&null!==r.error&&(void 0===(o=e.resetKeys)&&(o=[]),void 0===(a=i)&&(a=[]),o.length!==a.length||o.some((function(e,r){return!Object.is(e,a[r])})))&&(null==(t=(n=this.props).onResetKeysChange)||t.call(n,e.resetKeys,i),this.reset())},i.render=function(){var e=this.state.error,r=this.props,t=r.fallbackRender,o=r.FallbackComponent,a=r.fallback;if(null!==e){var u={error:e,resetErrorBoundary:this.resetErrorBoundary};if(n.isValidElement(a))return a;if("function"==typeof t)return t(u);if(o)return n.createElement(o,u);throw new Error("react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop")}return this.props.children},u}(n.Component);e.ErrorBoundary=u,e.useErrorHandler=function(e){var r=n.useState(null),t=r[0],o=r[1];if(null!=e)throw e;if(null!=t)throw t;return o},e.withErrorBoundary=function(e,r){var t=function(t){return n.createElement(u,r,n.createElement(e,t))},o=e.displayName||e.name||"Unknown";return t.displayName="withErrorBoundary("+o+")",t},Object.defineProperty(e,"__esModule",{value:!0})})); | ||
//# sourceMappingURL=react-error-boundary.umd.min.js.map |
{ | ||
"name": "react-error-boundary", | ||
"version": "3.1.3", | ||
"version": "3.1.4", | ||
"description": "Simple reusable React error boundary component", | ||
@@ -5,0 +5,0 @@ "main": "dist/react-error-boundary.cjs.js", |
@@ -46,3 +46,3 @@ <div align="center"> | ||
- [`ErrorBoundary` props](#errorboundary-props) | ||
- [`useErrorHandler(error?: Error)`](#useerrorhandlererror-error) | ||
- [`useErrorHandler(error?: unknown)`](#useerrorhandlererror-unknown) | ||
- [Issues](#issues) | ||
@@ -320,2 +320,4 @@ - [π Bugs](#-bugs) | ||
```javascript | ||
import { useErrorHandler } from 'react-error-boundary' | ||
function Greeting() { | ||
@@ -363,2 +365,4 @@ const [greeting, setGreeting] = React.useState(null) | ||
```javascript | ||
import { useErrorHandler } from 'react-error-boundary' | ||
function Greeting() { | ||
@@ -365,0 +369,0 @@ const [name, setName] = React.useState('') |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
447
56378
465