dry-ux 1.43.0 → 1.45.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,13 +1,22 @@
1
1
  import * as React from "react";
2
- export declare class ErrorBoundary extends React.Component<{
3
- fallback?: JSX.Element;
2
+ export interface IErrorBoundaryProps {
3
+ errorHandler?: (error?: Error, info?: React.ErrorInfo) => void;
4
+ onErrorCallback?: (error?: Error) => void;
5
+ rethrowError?: boolean;
6
+ fallback?: (error: Error, resetError: () => void) => JSX.Element;
4
7
  children: JSX.Element;
5
- }, {
6
- hasError: boolean;
7
- }> {
8
- constructor(props: any);
9
- static getDerivedStateFromError(error: any): {
10
- hasError: boolean;
8
+ }
9
+ interface IErrorBoundaryInnerState {
10
+ error: Error | null;
11
+ }
12
+ export declare class ErrorBoundary extends React.PureComponent<IErrorBoundaryProps, IErrorBoundaryInnerState> {
13
+ constructor(props: IErrorBoundaryProps);
14
+ static getDerivedStateFromError(error: Error): {
15
+ error: Error;
11
16
  };
12
- render(): JSX.Element & React.ReactNode;
17
+ componentDidCatch(error: Error, info: React.ErrorInfo): void;
18
+ render: () => JSX.Element & React.ReactNode;
19
+ private handleError;
20
+ private resetError;
13
21
  }
22
+ export {};
@@ -3,19 +3,43 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ErrorBoundary = void 0;
4
4
  const React = require("react");
5
5
  const ErrorScreen_1 = require("./ErrorScreen");
6
- class ErrorBoundary extends React.Component {
6
+ class ErrorBoundary extends React.PureComponent {
7
7
  constructor(props) {
8
8
  super(props);
9
- this.state = { hasError: false };
9
+ this.render = () => {
10
+ const { children, fallback = null } = this.props;
11
+ const { error } = this.state;
12
+ if (error) {
13
+ return fallback ? fallback(error, this.resetError.bind(this)) : React.createElement(ErrorScreen_1.ErrorScreen, null);
14
+ }
15
+ return children;
16
+ };
17
+ this.handleError = (error, info) => {
18
+ const { errorHandler, onErrorCallback, rethrowError } = this.props;
19
+ if (onErrorCallback) {
20
+ onErrorCallback(error);
21
+ }
22
+ if (errorHandler) {
23
+ errorHandler(error, info);
24
+ if (rethrowError) {
25
+ throw error;
26
+ }
27
+ return;
28
+ }
29
+ if (rethrowError) {
30
+ throw error;
31
+ }
32
+ };
33
+ this.state = { error: null };
10
34
  }
11
35
  static getDerivedStateFromError(error) {
12
- return { hasError: true };
36
+ return { error };
13
37
  }
14
- render() {
15
- if (this.state.hasError) {
16
- return this.props.fallback || React.createElement(ErrorScreen_1.ErrorScreen, null);
17
- }
18
- return this.props.children;
38
+ componentDidCatch(error, info) {
39
+ this.handleError(error, info);
40
+ }
41
+ resetError() {
42
+ this.setState({ error: null });
19
43
  }
20
44
  }
21
45
  exports.ErrorBoundary = ErrorBoundary;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dry-ux",
3
- "version": "1.43.0",
3
+ "version": "1.45.0",
4
4
  "description": "",
5
5
  "main": "dist/index",
6
6
  "scripts": {