diff --git a/src/components/ErrorBoundary.tsx b/src/components/ErrorBoundary.tsx new file mode 100644 index 0000000..e13ebe5 --- /dev/null +++ b/src/components/ErrorBoundary.tsx @@ -0,0 +1,37 @@ +import * as React from 'react'; + +class ErrorBoundary extends React.Component { + state: { + error?: Error; + }; + + constructor(props: any) { + super(props); + this.state = { }; + } + + componentDidCatch(error: Error, info: any) { + this.setState({ error }); + } + + render() { + if (this.state.error) { + return ( +
+

Something went wrong!

+
+            {this.state.error.message}
+          
+ +

Stack trace:

+
+            {this.state.error.stack}
+          
+
+ ); + } + return this.props.children; + } +} + +export default ErrorBoundary;