@ainias42/react-bootstrap-mobile 1.0.3 → 1.0.4

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ainias42/react-bootstrap-mobile",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "Mobile React Components",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -0,0 +1,46 @@
1
+ import { Block } from '@/Components/Layout/Block';
2
+ import { Heading } from '@/Components/Text/Heading';
3
+ import { Text } from '@/Components/Text/Text';
4
+ import React, { Component } from 'react';
5
+ import type { ReactNode } from 'react';
6
+
7
+ export type ErrorBoundaryProps = {
8
+ children: ReactNode;
9
+ formatError?: (error: unknown) => string;
10
+ showStack?: boolean;
11
+ };
12
+
13
+ type State = {
14
+ error: any;
15
+ };
16
+
17
+ export class ErrorBoundary extends Component<ErrorBoundaryProps, State> {
18
+ state = {
19
+ error: null,
20
+ } as State;
21
+
22
+ static getDerivedStateFromError(error: any) {
23
+ console.error('Got error', error);
24
+ return { error };
25
+ }
26
+
27
+ render() {
28
+ const { error } = this.state;
29
+ const { children, formatError, showStack } = this.props;
30
+ if (error) {
31
+ const message = formatError?.(error) || String(error);
32
+ let stack: string | undefined;
33
+ if (error instanceof Error) {
34
+ stack = error.stack;
35
+ }
36
+
37
+ return (
38
+ <Block>
39
+ <Heading>{message}</Heading>
40
+ {!!stack && showStack && <Text style={{ whiteSpace: 'pre' }}>{stack}</Text>}
41
+ </Block>
42
+ );
43
+ }
44
+ return children;
45
+ }
46
+ }
package/src/index.ts CHANGED
@@ -2,6 +2,7 @@ export * from './Size';
2
2
  export * from './treeshakeTest';
3
3
  export * from './TypeHelpers';
4
4
  export * from './WrongChildError';
5
+ export * from './Components/ErrorBoundary';
5
6
  export * from './Components/Flavor';
6
7
  export * from './Components/RbmComponentProps';
7
8
  export * from './helper/Characters';