react-error-boundary
Advanced tools
Comparing version
@@ -13,3 +13,5 @@ import * as React from 'react'; | ||
resetKeys?: Array<unknown>; | ||
fallback?: never; | ||
FallbackComponent: React.ComponentType<FallbackProps>; | ||
fallbackRender?: never; | ||
} | ||
@@ -24,2 +26,4 @@ declare function FallbackRender(props: FallbackProps): React.ReactElement<unknown, string | React.FunctionComponent | typeof React.Component> | null; | ||
resetKeys?: Array<unknown>; | ||
fallback?: never; | ||
FallbackComponent?: never; | ||
fallbackRender: typeof FallbackRender; | ||
@@ -35,2 +39,4 @@ } | ||
fallback: React.ReactElement<unknown, string | React.FunctionComponent | typeof React.Component> | null; | ||
FallbackComponent?: never; | ||
fallbackRender?: never; | ||
} | ||
@@ -52,3 +58,3 @@ declare type ErrorBoundaryProps = ErrorBoundaryPropsWithFallback | ErrorBoundaryPropsWithComponent | ErrorBoundaryPropsWithRender; | ||
componentDidUpdate(prevProps: ErrorBoundaryProps): void; | ||
render(): {} | null | undefined; | ||
render(): React.ReactNode; | ||
} | ||
@@ -55,0 +61,0 @@ declare function withErrorBoundary<P>(Component: React.ComponentType<P>, errorBoundaryProps: ErrorBoundaryProps): React.ComponentType<P>; |
@@ -10,3 +10,24 @@ 'use strict'; | ||
function _interopNamespace(e) { | ||
if (e && e.__esModule) return e; | ||
var n = Object.create(null); | ||
if (e) { | ||
Object.keys(e).forEach(function (k) { | ||
if (k !== 'default') { | ||
var d = Object.getOwnPropertyDescriptor(e, k); | ||
Object.defineProperty(n, k, d.get ? d : { | ||
enumerable: true, | ||
get: function () { | ||
return e[k]; | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
n['default'] = e; | ||
return Object.freeze(n); | ||
} | ||
var _inheritsLoose__default = /*#__PURE__*/_interopDefaultLegacy(_inheritsLoose); | ||
var React__namespace = /*#__PURE__*/_interopNamespace(React); | ||
@@ -110,4 +131,3 @@ var changedArray = function changedArray(a, b) { | ||
_proto.render = function render() { | ||
var error = this.state.error; // @ts-expect-error ts(2339) (at least one of these will be defined though, and we check for their existence) | ||
var error = this.state.error; | ||
var _this$props4 = this.props, | ||
@@ -124,3 +144,3 @@ fallbackRender = _this$props4.fallbackRender, | ||
if ( /*#__PURE__*/React.isValidElement(fallback)) { | ||
if ( /*#__PURE__*/React__namespace.isValidElement(fallback)) { | ||
return fallback; | ||
@@ -130,3 +150,3 @@ } else if (typeof fallbackRender === 'function') { | ||
} else if (FallbackComponent) { | ||
return /*#__PURE__*/React.createElement(FallbackComponent, _props); | ||
return /*#__PURE__*/React__namespace.createElement(FallbackComponent, _props); | ||
} else { | ||
@@ -141,7 +161,7 @@ throw new Error('react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop'); | ||
return ErrorBoundary; | ||
}(React.Component); | ||
}(React__namespace.Component); | ||
function withErrorBoundary(Component, errorBoundaryProps) { | ||
var Wrapped = function Wrapped(props) { | ||
return /*#__PURE__*/React.createElement(ErrorBoundary, errorBoundaryProps, /*#__PURE__*/React.createElement(Component, props)); | ||
return /*#__PURE__*/React__namespace.createElement(ErrorBoundary, errorBoundaryProps, /*#__PURE__*/React__namespace.createElement(Component, props)); | ||
}; // Format for display in DevTools | ||
@@ -156,3 +176,3 @@ | ||
function useErrorHandler(givenError) { | ||
var _React$useState = React.useState(null), | ||
var _React$useState = React__namespace.useState(null), | ||
error = _React$useState[0], | ||
@@ -159,0 +179,0 @@ setError = _React$useState[1]; |
import _inheritsLoose from '@babel/runtime/helpers/esm/inheritsLoose'; | ||
import { isValidElement, createElement, Component, useState } from 'react'; | ||
import * as React from 'react'; | ||
@@ -101,4 +101,3 @@ var changedArray = function changedArray(a, b) { | ||
_proto.render = function render() { | ||
var error = this.state.error; // @ts-expect-error ts(2339) (at least one of these will be defined though, and we check for their existence) | ||
var error = this.state.error; | ||
var _this$props4 = this.props, | ||
@@ -115,3 +114,3 @@ fallbackRender = _this$props4.fallbackRender, | ||
if ( /*#__PURE__*/isValidElement(fallback)) { | ||
if ( /*#__PURE__*/React.isValidElement(fallback)) { | ||
return fallback; | ||
@@ -121,3 +120,3 @@ } else if (typeof fallbackRender === 'function') { | ||
} else if (FallbackComponent) { | ||
return /*#__PURE__*/createElement(FallbackComponent, _props); | ||
return /*#__PURE__*/React.createElement(FallbackComponent, _props); | ||
} else { | ||
@@ -132,7 +131,7 @@ throw new Error('react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop'); | ||
return ErrorBoundary; | ||
}(Component); | ||
}(React.Component); | ||
function withErrorBoundary(Component, errorBoundaryProps) { | ||
var Wrapped = function Wrapped(props) { | ||
return /*#__PURE__*/createElement(ErrorBoundary, errorBoundaryProps, /*#__PURE__*/createElement(Component, props)); | ||
return /*#__PURE__*/React.createElement(ErrorBoundary, errorBoundaryProps, /*#__PURE__*/React.createElement(Component, props)); | ||
}; // Format for display in DevTools | ||
@@ -147,3 +146,3 @@ | ||
function useErrorHandler(givenError) { | ||
var _React$useState = useState(null), | ||
var _React$useState = React.useState(null), | ||
error = _React$useState[0], | ||
@@ -150,0 +149,0 @@ setError = _React$useState[1]; |
@@ -7,2 +7,24 @@ (function (global, factory) { | ||
function _interopNamespace(e) { | ||
if (e && e.__esModule) return e; | ||
var n = Object.create(null); | ||
if (e) { | ||
Object.keys(e).forEach(function (k) { | ||
if (k !== 'default') { | ||
var d = Object.getOwnPropertyDescriptor(e, k); | ||
Object.defineProperty(n, k, d.get ? d : { | ||
enumerable: true, | ||
get: function () { | ||
return e[k]; | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
n['default'] = e; | ||
return Object.freeze(n); | ||
} | ||
var React__namespace = /*#__PURE__*/_interopNamespace(React); | ||
function _setPrototypeOf(o, p) { | ||
@@ -120,4 +142,3 @@ _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { | ||
_proto.render = function render() { | ||
var error = this.state.error; // @ts-expect-error ts(2339) (at least one of these will be defined though, and we check for their existence) | ||
var error = this.state.error; | ||
var _this$props4 = this.props, | ||
@@ -134,3 +155,3 @@ fallbackRender = _this$props4.fallbackRender, | ||
if ( /*#__PURE__*/React.isValidElement(fallback)) { | ||
if ( /*#__PURE__*/React__namespace.isValidElement(fallback)) { | ||
return fallback; | ||
@@ -140,3 +161,3 @@ } else if (typeof fallbackRender === 'function') { | ||
} else if (FallbackComponent) { | ||
return /*#__PURE__*/React.createElement(FallbackComponent, _props); | ||
return /*#__PURE__*/React__namespace.createElement(FallbackComponent, _props); | ||
} else { | ||
@@ -151,7 +172,7 @@ throw new Error('react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop'); | ||
return ErrorBoundary; | ||
}(React.Component); | ||
}(React__namespace.Component); | ||
function withErrorBoundary(Component, errorBoundaryProps) { | ||
var Wrapped = function Wrapped(props) { | ||
return /*#__PURE__*/React.createElement(ErrorBoundary, errorBoundaryProps, /*#__PURE__*/React.createElement(Component, props)); | ||
return /*#__PURE__*/React__namespace.createElement(ErrorBoundary, errorBoundaryProps, /*#__PURE__*/React__namespace.createElement(Component, props)); | ||
}; // Format for display in DevTools | ||
@@ -166,3 +187,3 @@ | ||
function useErrorHandler(givenError) { | ||
var _React$useState = React.useState(null), | ||
var _React$useState = React__namespace.useState(null), | ||
error = _React$useState[0], | ||
@@ -169,0 +190,0 @@ setError = _React$useState[1]; |
@@ -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,e){return(t=Object.setPrototypeOf||function(r,e){return r.__proto__=e,r})(r,e)}var n={error:null},o=function(r){var o,a;function i(){for(var e,t=arguments.length,o=new Array(t),a=0;a<t;a++)o[a]=arguments[a];return(e=r.call.apply(r,[this].concat(o))||this).state=n,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}a=r,(o=i).prototype=Object.create(a.prototype),o.prototype.constructor=o,t(o,a),i.getDerivedStateFromError=function(r){return{error:r}};var u=i.prototype;return u.reset=function(){this.updatedWithError=!1,this.setState(n)},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,t=this.props,n=t.fallbackRender,o=t.FallbackComponent,a=t.fallback;if(null!==r){var i={error:r,resetErrorBoundary:this.resetErrorBoundary};if(e.isValidElement(a))return a;if("function"==typeof n)return n(i);if(o)return e.createElement(o,i);throw new Error("react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop")}return this.props.children},i}(e.Component);r.ErrorBoundary=o,r.useErrorHandler=function(r){var t=e.useState(null),n=t[0],o=t[1];if(r)throw r;if(n)throw n;return o},r.withErrorBoundary=function(r,t){var n=function(n){return e.createElement(o,t,e.createElement(r,n))},a=r.displayName||r.name||"Unknown";return n.displayName="withErrorBoundary("+a+")",n},Object.defineProperty(r,"__esModule",{value:!0})})); | ||
!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(r)throw r;if(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})})); | ||
//# sourceMappingURL=react-error-boundary.umd.min.js.map |
{ | ||
"name": "react-error-boundary", | ||
"version": "3.1.1", | ||
"version": "3.1.2", | ||
"description": "Simple reusable React error boundary component", | ||
@@ -5,0 +5,0 @@ "main": "dist/react-error-boundary.cjs.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
57943
2.54%505
10.5%