forked from PinSpace-Org/GistPin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChartErrorBoundary.tsx
More file actions
49 lines (42 loc) 路 1.02 KB
/
Copy pathChartErrorBoundary.tsx
File metadata and controls
49 lines (42 loc) 路 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
'use client';
import type { ReactNode } from 'react';
import { Component } from 'react';
interface ChartErrorBoundaryProps {
title: string;
children: ReactNode;
}
interface ChartErrorBoundaryState {
hasError: boolean;
}
export default class ChartErrorBoundary extends Component<
ChartErrorBoundaryProps,
ChartErrorBoundaryState
> {
state: ChartErrorBoundaryState = {
hasError: false,
};
static getDerivedStateFromError() {
return { hasError: true };
}
render() {
if (this.state.hasError) {
return (
<div
style={{
borderRadius: 20,
padding: 20,
background: '#fff7ed',
border: '1px solid #fed7aa',
color: '#9a3412',
}}
>
<div style={{ fontWeight: 800, marginBottom: 8 }}>{this.props.title}</div>
<div style={{ fontSize: 14 }}>
This chart failed to load. Refresh the page to try again.
</div>
</div>
);
}
return this.props.children;
}
}