Skip to content

Commit 913549c

Browse files
updated react example and changed export paradigm in react package
1 parent 28f253f commit 913549c

File tree

3 files changed

+37
-16
lines changed

3 files changed

+37
-16
lines changed

example/react/src/App.js

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,49 @@
1-
import React, { Component } from 'react';
2-
import './App.css';
3-
import { Exceptionless, ExceptionlessErrorBoundary } from "@exceptionless/react";
1+
import React, { Component } from "react";
2+
import "./App.css";
3+
import {
4+
Exceptionless,
5+
ExceptionlessErrorBoundary,
6+
} from "@exceptionless/react";
47

58
class App extends Component {
9+
constructor(props) {
10+
super(props);
11+
this.state = {
12+
error: false,
13+
};
14+
}
615
async componentDidMount() {
7-
await Exceptionless.startup(c => {
8-
c.apiKey = "LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw";
9-
c.serverUrl = "http://localhost:5000";
16+
await Exceptionless.startup((c) => {
17+
c.apiKey = "YOUR API KEY";
1018
c.useDebugLogger();
1119

1220
c.defaultTags.push("Example", "React");
13-
})
21+
});
1422
}
1523

16-
render() {
17-
return (
18-
<ExceptionlessErrorBoundary>
24+
throwErrorInComponent = () => {
25+
this.setState({ error: true });
26+
};
27+
28+
renderExample = () => {
29+
if (this.state.error) {
30+
throw new Error("I crashed!");
31+
} else {
32+
return (
1933
<div className="App">
2034
<header className="App-header">
2135
<h1 className="App-title">Exceptionless React Sample</h1>
36+
<button onClick={this.throwErrorInComponent}>Throw Error</button>
2237
</header>
23-
<p className="App-intro">
24-
To get started, edit <code>src/App.js</code> and save to reload.
25-
</p>
2638
</div>
39+
);
40+
}
41+
};
42+
43+
render() {
44+
return (
45+
<ExceptionlessErrorBoundary>
46+
{this.renderExample()}
2747
</ExceptionlessErrorBoundary>
2848
);
2949
}

packages/react/src/ExceptionlessErrorBoundary.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ type ErrorState = {
55
hasError: boolean;
66
};
77

8-
export class ExceptionlessErrorBoundary extends Component<{}, ErrorState> {
8+
export default class ExceptionlessErrorBoundary extends Component<{}, ErrorState> {
99
constructor(props) {
1010
super(props);
1111
}

packages/react/src/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
export { Exceptionless } from "@exceptionless/browser";
1+
import { Exceptionless } from "@exceptionless/browser";
2+
import ExceptionlessErrorBoundary from "./ExceptionlessErrorBoundary.js";
23

3-
export { ExceptionlessErrorBoundary } from "./ExceptionlessErrorBoundary.js";
4+
export { Exceptionless, ExceptionlessErrorBoundary }

0 commit comments

Comments
 (0)