-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathIndex.jsx
More file actions
59 lines (51 loc) · 1.47 KB
/
Index.jsx
File metadata and controls
59 lines (51 loc) · 1.47 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
50
51
52
53
54
55
56
57
58
59
import * as React from 'react';
import { withProfiler } from '@sentry/react';
function ProfilerTestComponent() {
return <div id="profiler-test">withProfiler works</div>;
}
ProfilerTestComponent.customStaticMethod = () => 'static method works';
const ProfiledComponent = withProfiler(ProfilerTestComponent);
const Index = () => {
const [caughtError, setCaughtError] = React.useState(false);
const [uncaughtError, setUncaughtError] = React.useState(false);
return (
<>
<div>
<ProfiledComponent />
<SampleErrorBoundary>
<h1>React 19</h1>
{caughtError && <Throw error="caught" />}
<button id="caughtError-button" onClick={() => setCaughtError(true)}>
Throw caught error
</button>
</SampleErrorBoundary>
</div>
<div>
{uncaughtError && <Throw error="uncaught" />}
<button id="uncaughtError-button" onClick={() => setUncaughtError(true)}>
Throw uncaught error
</button>
</div>
</>
);
};
function Throw({ error }) {
throw new Error(`${error} error`);
}
class SampleErrorBoundary extends React.Component {
constructor(props) {
super(props);
this.state = { error: null };
}
componentDidCatch(error, errorInfo) {
this.setState({ error });
// no-op
}
render() {
if (this.state.error) {
return <div>Caught an error: {JSON.stringify(this.state.error)}</div>;
}
return this.props.children;
}
}
export default Index;