-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathrollbar-configuration.js
43 lines (34 loc) · 1.11 KB
/
rollbar-configuration.js
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
'use client';
// EXPERIMENTAL
// NOT EXPORTED AS PART OF PUBLIC API YET: no current test coverage
// PURPOSE provide a wrapping around Rollbar configuration for a subtree
import { Component } from 'react';
import PropTypes from 'prop-types';
import { Context, getRollbarFromContext } from './provider';
export class RollbarConfiguration extends Component {
static propTypes = {
options: PropTypes.object.isRequired,
children: PropTypes.node,
};
static contextType = Context;
constructor(props) {
super(props);
this.state = { parentConfig: null };
}
componentDidMount() {
const rollbar = getRollbarFromContext(this.context);
const { options } = this.props;
// TODO: need to clone this somehow to prevent downstream changes from manipulating it
const parentConfig = ((o) => o)(rollbar.options);
this.setState({ parentConfig });
rollbar.configure(options);
}
componentWillUnmount() {
const rollbar = getRollbarFromContext(this.context);
const { parentConfig } = this.state;
rollbar.configure(parentConfig);
}
render() {
return this.props.children;
}
}