@hoosei/voxweave-react
Version:
A customizable and interactive voice UI component for React applications
3 lines (2 loc) • 1.61 kB
JavaScript
;Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("react"),c=i.createContext(null),d={didCatch:!1,error:null};class h extends i.Component{constructor(r){super(r),this.resetErrorBoundary=this.resetErrorBoundary.bind(this),this.state=d}static getDerivedStateFromError(r){return{didCatch:!0,error:r}}resetErrorBoundary(){const{error:r}=this.state;if(r!==null){for(var t,e,n=arguments.length,a=new Array(n),o=0;o<n;o++)a[o]=arguments[o];(t=(e=this.props).onReset)===null||t===void 0||t.call(e,{args:a,reason:"imperative-api"}),this.setState(d)}}componentDidCatch(r,t){var e,n;(e=(n=this.props).onError)===null||e===void 0||e.call(n,r,t)}componentDidUpdate(r,t){const{didCatch:e}=this.state,{resetKeys:n}=this.props;if(e&&t.error!==null&&m(r.resetKeys,n)){var a,o;(a=(o=this.props).onReset)===null||a===void 0||a.call(o,{next:n,prev:r.resetKeys,reason:"keys"}),this.setState(d)}}render(){const{children:r,fallbackRender:t,FallbackComponent:e,fallback:n}=this.props,{didCatch:a,error:o}=this.state;let s=r;if(a){const u={error:o,resetErrorBoundary:this.resetErrorBoundary};if(typeof t=="function")s=t(u);else if(e)s=i.createElement(e,u);else if(n!==void 0)s=n;else throw o}return i.createElement(c.Provider,{value:{didCatch:a,error:o,resetErrorBoundary:this.resetErrorBoundary}},s)}}function m(){let l=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[],r=arguments.length>1&&arguments[1]!==void 0?arguments[1]:[];return l.length!==r.length||l.some((t,e)=>!Object.is(t,r[e]))}exports.ErrorBoundary=h;exports.ErrorBoundaryContext=c;
//# sourceMappingURL=index12.js.map