Skip to content

Commit b86306b

Browse files
authored
Merge pull request #6 from hally9k/master
withErrorBoundary decorator function.
2 parents 2d39ffc + 454aa4b commit b86306b

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/ErrorBoundary.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ type State = {
1818
info: ?ErrorInfo,
1919
};
2020

21-
class ErrorBoundary extends Component {
21+
class ErrorBoundary extends Component<Props, State> {
2222
props: Props;
2323
state: State;
2424

25+
setState: Function
26+
2527
static defaultProps = {
2628
FallbackComponent: ErrorBoundaryFallbackComponent,
2729
};
@@ -61,4 +63,16 @@ class ErrorBoundary extends Component {
6163
}
6264
}
6365

66+
67+
export const withErrorBoundary: Function = (
68+
Component: Class<React.Component<*>>,
69+
FallbackComponent: Class<React.Component<*>>,
70+
onError: Function
71+
): Function => props => (
72+
<ErrorBoundary FallbackComponent={FallbackComponent} onError={onError}>
73+
<Component {...props} />
74+
</ErrorBoundary>
75+
);
76+
77+
6478
export default ErrorBoundary;

src/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/** @flow */
22

33
import ErrorBoundaryFallbackComponent from './ErrorBoundaryFallbackComponent';
4-
import ErrorBoundary from './ErrorBoundary';
4+
import ErrorBoundary, { withErrorBoundary } from './ErrorBoundary';
55

66
export default ErrorBoundary;
7-
export {ErrorBoundary, ErrorBoundaryFallbackComponent};
7+
export {ErrorBoundary, withErrorBoundary, ErrorBoundaryFallbackComponent};

0 commit comments

Comments
 (0)