diff options
| author | Ariel Costas Guerrero <94913521+arielcostas@users.noreply.github.com> | 2025-03-03 22:54:36 +0100 |
|---|---|---|
| committer | Ariel Costas Guerrero <94913521+arielcostas@users.noreply.github.com> | 2025-03-03 22:54:36 +0100 |
| commit | 2e90c813d0cf924bb9e8b383c1202aae15b14684 (patch) | |
| tree | d7dac941a482a8f0ef82645d0ffd05e1efc68e5e /src/ErrorBoundary.tsx | |
| parent | 797c5f551b1bb6ddb139704eb9e8953c3bc1a8c8 (diff) | |
Add theme provider and errorBoundary
Diffstat (limited to 'src/ErrorBoundary.tsx')
| -rw-r--r-- | src/ErrorBoundary.tsx | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/ErrorBoundary.tsx b/src/ErrorBoundary.tsx new file mode 100644 index 0000000..d3f5a60 --- /dev/null +++ b/src/ErrorBoundary.tsx @@ -0,0 +1,34 @@ +import React, { Component, ReactNode } from 'react'; + +interface ErrorBoundaryProps { + children: ReactNode; +} + +interface ErrorBoundaryState { + hasError: boolean; +} + +class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> { + constructor(props: ErrorBoundaryProps) { + super(props); + this.state = { hasError: false }; + } + + static getDerivedStateFromError(_: Error): ErrorBoundaryState { + return { hasError: true }; + } + + componentDidCatch(error: Error, errorInfo: React.ErrorInfo) { + console.error("Uncaught error:", error, errorInfo); + } + + render() { + if (this.state.hasError) { + return <h1>Something went wrong.</h1>; + } + + return this.props.children; + } +} + +export default ErrorBoundary;
\ No newline at end of file |
