forked from exceptionless/Exceptionless.JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHooksExampleApp.js
More file actions
61 lines (52 loc) · 1.81 KB
/
HooksExampleApp.js
File metadata and controls
61 lines (52 loc) · 1.81 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
60
61
import React, { useEffect, useState } from "react";
import "./App.css";
import { Exceptionless, ExceptionlessErrorBoundary } from "@exceptionless/react";
const HooksExampleApp = () => {
const [error, setError] = useState(false);
useEffect(() => {
startExceptionless();
}, []);
const startExceptionless = async () => {
await Exceptionless.startup((c) => {
c.apiKey = "LhhP1C9gijpSKCslHHCvwdSIz298twx271nTest";
c.serverUrl = "https://localhost:5100";
c.useDebugLogger();
c.defaultTags.push("Example", "React");
});
};
const throwErrorInComponent = () => {
setError(true);
};
const submitMessage = () => {
Exceptionless.submitLog("Hello, world!");
};
const tryCatchExample = () => {
try {
throw new Error("Caught in the try/catch");
} catch (error) {
Exceptionless.submitException(error);
}
};
const renderExample = () => {
if (error) {
throw new Error("I crashed!");
} else {
return (
<div className="App">
<header className="App-header">
<div className="container">
<h1 className="App-title">Exceptionless React Sample</h1>
<p>By pressing the button below, an uncaught error will be thrown inside your component. This will automatically be sent to Exceptionless.</p>
<button onClick={throwErrorInComponent}>Simulate Error</button>
<p>The following buttons simulated handled events outside the component.</p>
<button onClick={submitMessage}>Submit Message</button>
<button onClick={tryCatchExample}>Try/Catch Example</button>
</div>
</header>
</div>
);
}
};
return <ExceptionlessErrorBoundary>{renderExample()}</ExceptionlessErrorBoundary>;
};
export default HooksExampleApp;