1
0
mirror of https://github.com/trezor/trezor-wallet synced 2025-01-22 05:51:18 +00:00
trezor-wallet/src/support/ErrorBoundary.js
2018-10-10 14:39:42 +02:00

27 lines
612 B
JavaScript

import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import RedBox from 'redbox-react';
class ErrorBoundary extends PureComponent {
constructor(props) {
super(props);
this.state = { hasError: false, error: false };
}
componentDidCatch(error) {
this.setState({ hasError: true, error });
}
render() {
if (this.state.hasError) {
return <RedBox error={this.state.error} />;
}
return this.props.children;
}
}
ErrorBoundary.propTypes = {
children: PropTypes.node,
};
export default ErrorBoundary;