10
10
11
11
---
12
12
13
-
14
13
React features to enhance using Rollbar.js in React Applications.
15
14
16
15
This SDK provides a wrapper around the base [ Rollbar.js] SDK in order to provide an
17
16
SDK that matches the intention of how to build React Apps with a declarative API, features for the latest React API like
18
17
hooks and ErrorBoundaries, as well as simplify using Rollbar within a React SPA.
19
18
20
19
## Key benefits of using Rollbar React are:
20
+
21
21
- ** Telemetry:** The telemetry timeline provides a list of “breadcrumbs” events that can help developers understand and fix problems in their client-side javascript. <a href =" https://docs.rollbar.com/docs/rollbarjs-telemetry " >Learn more about telemetry</a >.
22
22
- ** Automatic error grouping:** Rollbar aggregates Occurrences caused by the same error into Items that represent application issues. <a href =" https://docs.rollbar.com/docs/grouping-occurrences " >Learn more about reducing log noise</a >.
23
23
- ** Advanced search:** Filter items by many different properties. <a href =" https://docs.rollbar.com/docs/search-items " >Learn more about search</a >.
24
24
- ** Customizable notifications:** Rollbar supports several messaging and incident management tools where your team can get notified about errors and important events by real-time alerts. <a href =" https://docs.rollbar.com/docs/notifications " >Learn more about Rollbar notifications</a >.
25
25
26
-
27
26
### In Beta
28
27
29
28
It is currently in a public Beta release right now as we push towards a 1.0 release that will have all of the features
@@ -153,11 +152,7 @@ const rollbarConfig = {
153
152
};
154
153
155
154
export function App (props ) {
156
- return (
157
- < Provider config= {rollbarConfig}>
158
- …
159
- < / Provider>
160
- );
155
+ return < Provider config= {rollbarConfig}> …< / Provider> ;
161
156
}
162
157
```
163
158
@@ -180,11 +175,7 @@ const rollbarConfig = {
180
175
const rollbar = new Rollbar (rollbarConfig);
181
176
182
177
export function App (props ) {
183
- return (
184
- < Provider instance= {rollbar}>
185
- …
186
- < / Provider>
187
- );
178
+ return < Provider instance= {rollbar}> …< / Provider> ;
188
179
}
189
180
```
190
181
@@ -206,11 +197,7 @@ import { Provider } from '@rollbar/react';
206
197
const rollbarClient = new Client (' POST_CLIENT_ITEM_ACCESS_TOKEN' );
207
198
208
199
export function App (props ) {
209
- return (
210
- < Provider instance= {rollbarClient .rollbar }>
211
- …
212
- < / Provider>
213
- );
200
+ return < Provider instance= {rollbarClient .rollbar }> …< / Provider> ;
214
201
}
215
202
```
216
203
@@ -243,9 +230,7 @@ const rollbarConfig = {
243
230
export function App (props ) {
244
231
return (
245
232
< Provider config= {rollbarConfig}>
246
- < ErrorBoundary>
247
- …
248
- < / ErrorBoundary>
233
+ < ErrorBoundary> …< / ErrorBoundary>
249
234
< / Provider>
250
235
);
251
236
}
@@ -272,7 +257,15 @@ const rollbarConfig = {
272
257
export function App (props ) {
273
258
return (
274
259
< Provider config= {rollbarConfig}>
275
- < ErrorBoundary level= {LEVEL_WARN } errorMessage= " Error in React render" extra= {(error , info ) => info .componentStack .includes (' Experimental' ) ? { experiment: true } : {} }>
260
+ < ErrorBoundary
261
+ level= {LEVEL_WARN }
262
+ errorMessage= " Error in React render"
263
+ extra= {(error , info ) =>
264
+ info .componentStack .includes (' Experimental' )
265
+ ? { experiment: true }
266
+ : {}
267
+ }
268
+ >
276
269
…
277
270
< / ErrorBoundary>
278
271
< / Provider>
@@ -297,7 +290,9 @@ const rollbarConfig = {
297
290
environment: ' production' ,
298
291
};
299
292
300
- const ErrorDisplay = ({ error, resetError }) => ( // <-- props passed to fallbackUI component
293
+ const ErrorDisplay = (
294
+ { error, resetError }, // <-- props passed to fallbackUI component
295
+ ) => (
301
296
< div>
302
297
< h1> A following error has occured: < / h1>
303
298
< p> {error .toString ()}< / p>
@@ -335,11 +330,7 @@ import React from 'react';
335
330
import { RollbarContext } from ' @rollbar/react' ;
336
331
337
332
function HomePage () {
338
- return (
339
- < RollbarContext context= " home" >
340
- …
341
- < / RollbarContext>
342
- )
333
+ return < RollbarContext context= " home" > …< / RollbarContext> ;
343
334
}
344
335
```
345
336
@@ -377,7 +368,7 @@ const Routes = () => (
377
368
< / Route>
378
369
< / Switch>
379
370
< / Router>
380
- )
371
+ );
381
372
382
373
export default Routes ;
383
374
```
@@ -392,11 +383,9 @@ import { RollbarContext } from '@rollbar/react';
392
383
export default function About (props ) {
393
384
return (
394
385
< Route path= " /about" >
395
- < RollbarContext context= " /about" >
396
- …
397
- < / RollbarContext>
386
+ < RollbarContext context= " /about" > …< / RollbarContext>
398
387
< / Route>
399
- )
388
+ );
400
389
}
401
390
```
402
391
@@ -474,7 +463,8 @@ const ROUTE_PARAMS_RE = /\/\d+/g;
474
463
475
464
const historyListener = historyContext (rollbar, {
476
465
// optional: default uses location.pathname
477
- formatter : (location , action ) => location .pathname .replace (ROUTE_PARAMS_RE , ' ' ),
466
+ formatter : (location , action ) =>
467
+ location .pathname .replace (ROUTE_PARAMS_RE , ' ' ),
478
468
// optional: true return sets Rollbar context
479
469
filter : (location , action ) => ! location .pathname .includes (' admin' ),
480
470
});
@@ -513,11 +503,7 @@ function ContactDetails({ contactId }) {
513
503
}
514
504
}, [contactId]);
515
505
516
- return (
517
- < div>
518
- …
519
- < / div>
520
- );
506
+ return < div> …< / div> ;
521
507
}
522
508
```
523
509
@@ -535,11 +521,7 @@ import { useRollbarContext } from '@rollbar/react';
535
521
function HomePage (props ) {
536
522
useRollbarContext (' home#index' );
537
523
538
- return (
539
- < div>
540
- …
541
- < / div>
542
- );
524
+ return < div> …< / div> ;
543
525
}
544
526
545
527
// src/pages/UsersPage.js
@@ -549,9 +531,7 @@ import UserTable from '../components/users/UserTable';
549
531
function UsersPage (props ) {
550
532
useRollbarContext (' users#list' );
551
533
552
- return (
553
- < UserTable data= {props .users } / >
554
- );
534
+ return < UserTable data= {props .users } / > ;
555
535
}
556
536
557
537
// src/pages/UserDetailsPage.js
@@ -561,9 +541,7 @@ import UserDetails from '../components/users/UserDetails';
561
541
function UserDetailsPage (props ) {
562
542
useRollbarContext (' users#details' );
563
543
564
- return (
565
- < UserDetails user= {props .user } / >
566
- );
544
+ return < UserDetails user= {props .user } / > ;
567
545
}
568
546
```
569
547
@@ -585,7 +563,7 @@ Here is a simple example of using it once the current user has been determined:
585
563
``` javascript
586
564
import { useState } from ' react' ;
587
565
import { useRollbarPerson } from ' @rollbar/react' ;
588
- import LoggedInHome from ' ./LoggedInHome' ;
566
+ import LoggedInHome from ' ./LoggedInHome' ;
589
567
import LoggedOutHome from ' ./LoggedOutHome' ;
590
568
591
569
function Home () {
@@ -596,7 +574,7 @@ function Home() {
596
574
(async () => {
597
575
const user = await Auth .getCurrentUser ();
598
576
setCurrentUser (user);
599
- })()
577
+ })();
600
578
});
601
579
602
580
if (currentUser != null ) {
@@ -642,28 +620,23 @@ function BookDetails({ bookId }) {
642
620
643
621
useRollbarCaptureEvent (book, LEVEL_INFO ); // <-- only fires when book changes
644
622
645
- return (
646
- < div>
647
- …
648
- < / div>
649
- )
623
+ return < div> …< / div> ;
650
624
}
651
625
```
652
626
653
-
654
- [ Rollbar ] : https://rollbar.com
655
- [ Rollbar Docs ] : https://docs.rollbar.com
656
- [ Rollbar.js ] : https://github.com/rollbar/rollbar.js
657
- [ Rollbar.js Setup Instructions ] : https://github.com/rollbar/rollbar.js/#setup-instructions
658
- [ React Native SDK ] : https://github.com/rollbar/rollbar-react-native
659
- [ Telemetry ] : https://docs.rollbar.com/docs/rollbarjs-telemetry
660
- [ `Provider` ] : #provider-component
661
- [ `ErrorBoundary` ] : #errorboundary-component
662
- [ `RollbarContext` ] : #rollbarcontext-component
663
- [ Functional Components ] : https://reactjs.org/docs/components-and-props.html#function-and-class-components
664
- [ React Context ] : https://reactjs.org/docs/context.html
665
- [ Error Boundaries ] : https://reactjs.org/docs/error-boundaries.html
666
- [ React Hooks API ] : https://reactjs.org/docs/hooks-intro.html
627
+ [ rollbar ] : https://rollbar.com
628
+ [ rollbar docs ] : https://docs.rollbar.com
629
+ [ rollbar.js ] : https://github.com/rollbar/rollbar.js
630
+ [ rollbar.js setup instructions ] : https://github.com/rollbar/rollbar.js/#setup-instructions
631
+ [ react native sdk ] : https://github.com/rollbar/rollbar-react-native
632
+ [ telemetry ] : https://docs.rollbar.com/docs/rollbarjs-telemetry
633
+ [ `provider` ] : #provider-component
634
+ [ `errorboundary` ] : #errorboundary-component
635
+ [ `rollbarcontext` ] : #rollbarcontext-component
636
+ [ functional components ] : https://reactjs.org/docs/components-and-props.html#function-and-class-components
637
+ [ react context ] : https://reactjs.org/docs/context.html
638
+ [ error boundaries ] : https://reactjs.org/docs/error-boundaries.html
639
+ [ react hooks api ] : https://reactjs.org/docs/hooks-intro.html
667
640
[ history ] : https://www.npmjs.com/package/history
668
641
[ history.location ] : https://github.com/ReactTraining/history/blob/master/docs/api-reference.md#location
669
642
[ history.action ] : https://github.com/ReactTraining/history/blob/master/docs/api-reference.md#action
0 commit comments