Skip to content

Commit 32ff49a

Browse files
authored
docs(react): Add react package info to README (#2686)
* ref(gatsby): Require @sentry/react in browser plugin * docs(react): Update README
1 parent 1f4772e commit 32ff49a

File tree

2 files changed

+80
-3
lines changed

2 files changed

+80
-3
lines changed

packages/gatsby/src/gatsby-browser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
exports.onClientEntry = function(_, pluginParams) {
22
require.ensure(['@sentry/react', '@sentry/apm'], function(require) {
3-
const Sentry = require('@sentry/browser');
3+
const Sentry = require('@sentry/react');
44
const TracingIntegration = require('@sentry/apm').Integrations.Tracing;
55
const tracesSampleRate = pluginParams.tracesSampleRate !== undefined ? pluginParams.tracesSampleRate : 0;
66
const integrations = [...(pluginParams.integrations || [])];

packages/react/README.md

Lines changed: 79 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,86 @@
77

88
# Official Sentry SDK for ReactJS
99

10-
Note this library is in active development and not ready for production usage.
11-
1210
## Links
1311

1412
- [Official SDK Docs](https://docs.sentry.io/quickstart/)
1513
- [TypeDoc](http://getsentry.github.io/sentry-javascript/)
14+
15+
## General
16+
17+
This package is a wrapper around `@sentry/browser`, with added functionality related to React. All methods available in
18+
`@sentry/browser` can be imported from `@sentry/react`.
19+
20+
To use this SDK, call `Sentry.init(options)` before you mount your React component.
21+
22+
```javascript
23+
import React from 'react';
24+
import ReactDOM from "react-dom";
25+
import * as Sentry from '@sentry/react';
26+
27+
Sentry.init({
28+
dsn: '__DSN__',
29+
// ...
30+
});
31+
32+
// ...
33+
34+
ReactDOM.render(<App />, rootNode);
35+
36+
// Can also use with React Concurrent Mode
37+
// ReactDOM.createRoot(rootNode).render(<App />);
38+
```
39+
40+
### ErrorBoundary
41+
42+
`@sentry/react` exports an ErrorBoundary component that will automatically send Javascript errors from inside a
43+
component tree to Sentry, and set a fallback UI. Requires React version >= 16.
44+
45+
> app.js
46+
```javascript
47+
import React from 'react';
48+
import * as Sentry from '@sentry/react';
49+
50+
function FallbackComponent() {
51+
return (
52+
<div>An error has occured</div>
53+
)
54+
}
55+
56+
class App extends React.Component {
57+
render() {
58+
return (
59+
<Sentry.ErrorBoundary fallback={FallbackComponent} showDialog>
60+
<OtherComponents />
61+
</Sentry.ErrorBoundary>
62+
)
63+
}
64+
}
65+
66+
export default App;
67+
```
68+
69+
### Profiler
70+
71+
`@sentry/react` exports a Profiler component that leverages the `@sentry/apm` Tracing integration to add React related
72+
spans to transactions. If the Tracing integration is not enabled, the Profiler component will not work. The Profiler
73+
tracks component mount, render duration and updates. Requires React version >= 15.
74+
75+
> app.js
76+
```javascript
77+
import React from 'react';
78+
import * as Sentry from '@sentry/react';
79+
80+
class App extends React.Component {
81+
render() {
82+
return (
83+
<FancyComponent>
84+
<InsideComponent someProp={2} />
85+
<AnotherComponent />
86+
</FancyComponent>
87+
)
88+
}
89+
}
90+
91+
export default Sentry.withProfiler(App);
92+
```

0 commit comments

Comments
 (0)