You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -39,7 +40,7 @@ After following those 2 steps, you will be ready.
39
40
### Install Rollbar React SDK
40
41
41
42
We are hosting our `@rollbar` scoped packages in Github Packages. In order to use this you will need to follow the
42
-
instructions for [Installing a Package from Github Packages](https://docs.github.com/en/packages/guides/configuring-npm-for-use-with-github-packages#installing-a-package)
43
+
instructions for [Installing a Package from Github Packages][1]
43
44
44
45
In the same directory as your `package.json` file, add a `.npmrc` file with the following:
45
46
@@ -59,13 +60,62 @@ To install with `yarn`:
59
60
yarn add @rollbar/react
60
61
```
61
62
63
+
To install by adding to `package.json` (as suggested by [Github Packages docs][1]), add the following to your project's
64
+
`package.json` file:
65
+
66
+
```json
67
+
…
68
+
"dependencies": {
69
+
"@rollbar/react": "^0.7.0",
70
+
…
71
+
}
72
+
…
73
+
```
74
+
75
+
then run either using `npm` or `yarn` (or other package manager):
76
+
77
+
```shell
78
+
npm install
79
+
# OR
80
+
yarn install
81
+
```
82
+
62
83
## Usage and Reference
63
84
64
85
The React SDK is very new and has not been given the full documentation treatment we expect to get from [Rollbar Docs],
65
86
but that will be coming shortly and a direct link will be put here for your reference.
66
87
67
88
In the meantime, the basic usage reference is available below.
68
89
90
+
### Simplest Usage Possible
91
+
92
+
To get you started quickly, here is an example that will get you started right away by providing the easiest and simplest
93
+
usage possible:
94
+
95
+
```javascript
96
+
importReactfrom'react';
97
+
import { Provider, ErrorBoundary } from'@rollbar/react'; // <-- Provider imports 'rollbar' for us
98
+
99
+
// same configuration you would create for the Rollbar.js SDK
100
+
constrollbarConfig= {
101
+
accessToken:'POST_CLIENT_ITEM_ACCESS_TOKEN',
102
+
environment:'production',
103
+
};
104
+
105
+
exportdefaultfunctionApp() {
106
+
return (
107
+
{/* Provider instantiates Rollbar client instance handling any uncaught errors or unhandled promises in the browser */}
108
+
<Provider config={rollbarConfig}>
109
+
{/* ErrorBoundary catches all React errors in the tree below and logs them to Rollbar */}
110
+
<ErrorBoundary>
111
+
// all other app providers and components - Rollbar will just work
112
+
…
113
+
</ErrorBoundary>
114
+
</Provider>
115
+
);
116
+
};
117
+
```
118
+
69
119
## Components
70
120
71
121
The following components are available as named imports from `@rollbar/react`.
@@ -162,12 +212,12 @@ introduced in React 16.
162
212
The `ErrorBoundary` is used to wrap any tree or subtree in your React App to catch React Errors and log them to Rollbar
163
213
automatically.
164
214
165
-
The `ErrorBoundary` relies on the [`Provider`](#provider-component) above for the instance of Rollbar, so it will utilize
215
+
The `ErrorBoundary` relies on the [`Provider`] above for the instance of Rollbar, so it will utilize
166
216
whatever configuration has been provided.
167
217
168
218
#### Simple Usage
169
219
170
-
You can add an `ErrorBoundary` component to the top of your tree right after the `Provider` with no additional props
220
+
You can add an `ErrorBoundary` component to the top of your tree right after the [`Provider`] with no additional props
171
221
and it will just work:
172
222
173
223
```javascript
@@ -261,7 +311,7 @@ messages to [Rollbar].
261
311
This works for your `ErrorBoundary` from above or any other log or message sent to [Rollbar] while the `RollbarContext`
262
312
is mounted on the tree.
263
313
264
-
Like `ErrorBoundary` above, `RollbarContext` relies on a `Provider` for an instance of a [Rollbar.js] client.
314
+
Like `ErrorBoundary` above, `RollbarContext` relies on a [`Provider`] for an instance of a [Rollbar.js] client.
265
315
266
316
#### Basic Usage
267
317
@@ -338,10 +388,6 @@ export default function About(props) {
338
388
}
339
389
```
340
390
341
-
#### Controlling when the context is set
342
-
343
-
-`onRender` (optional) is any value that will be treated as a `Boolean` (truthy or falsey)
344
-
345
391
## Functions
346
392
347
393
The following functions are available as named imports from `@rollbar/react`.
0 commit comments