core-native
Version:
A lightweight framework based on React Native + Redux + Redux Saga, in strict TypeScript.
27 lines • 998 B
JavaScript
import React from "react";
import { connect } from "react-redux";
import { ReactLifecycleException } from "../Exception";
import { errorAction } from "../reducer";
class Component extends React.PureComponent {
constructor() {
super(...arguments);
this.state = { exception: null };
}
componentDidUpdate(prevProps) {
// Support page recovery
if (this.props.children !== prevProps.children) {
this.setState({ exception: null });
}
}
componentDidCatch(error, errorInfo) {
const exception = new ReactLifecycleException(error.message, errorInfo.componentStack);
this.props.dispatch(errorAction(exception));
this.setState({ exception });
}
render() {
return this.state.exception ? this.props.render(this.state.exception) : this.props.children;
}
}
Component.defaultProps = { render: () => null };
export const ErrorBoundary = connect()(Component);
//# sourceMappingURL=ErrorBoundary.js.map