1
0
mirror of https://github.com/trezor/trezor-wallet synced 2025-07-04 13:52:38 +00:00
trezor-wallet/src/js/support/ErrorBoundary.js
2018-08-16 15:56:39 +02:00

26 lines
685 B
JavaScript

import React, { Component } from 'react';
class ErrorBoundary extends Component {
constructor(props) {
super(props);
this.state = { hasError: false };
}
componentDidCatch(error, info) {
// Display fallback UI
this.setState({ hasError: true });
console.error('error', error);
// You can also log the error to an error reporting service
// logErrorToMyService(error, info);
}
render() {
if (this.state.hasError) {
// You can render any custom fallback UI
return <div>Something went wrong.</div>;
}
return this.props.children;
}
}
export default ErrorBoundary;