Skip to content

Commit 877e67c

Browse files
authored
feat: export provider context for class components to use (#38)
1 parent 899988f commit 877e67c

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

index.d.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { Component, ReactNode } from "react";
1+
import { Component, Context as ReactContext, ReactNode } from "react";
22
import Rollbar, { Callback, Configuration } from "rollbar";
3+
import { RollbarInstance, BaseOptions, RollbarCtor } from "./src/provider";
34

45
export const LEVEL_DEBUG = "debug";
56
export const LEVEL_INFO = "info";
@@ -53,6 +54,15 @@ interface ProviderState {
5354

5455
export class Provider extends Component<ProviderProps, ProviderState> {}
5556

57+
interface ContextInterface {
58+
[RollbarInstance]: Rollbar;
59+
[BaseOptions]: Configuration;
60+
[RollbarCtor]: new (options: Configuration) => Rollbar;
61+
}
62+
63+
export const Context: ReactContext<ContextInterface>;
64+
65+
export function getRollbarFromContext(context: Context): Rollbar;
5666
export function useRollbar(): Rollbar;
5767
export function useRollbarConfiguration(config: Rollbar.Configuration): void;
5868
export function useRollbarContext(ctx?: string, isLayout?: boolean): void;

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export { LEVEL_DEBUG, LEVEL_INFO, LEVEL_WARN, LEVEL_ERROR, LEVEL_CRITICAL } from './constants';
22
export { historyContext } from './history-context';
3-
export { Provider } from './provider';
3+
export { Provider, Context, getRollbarFromContext } from './provider';
44
export { ErrorBoundary } from './error-boundary';
55
export { RollbarContext } from './rollbar-context';
66
export { isValidLevel } from './utils';

src/provider.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import { isRollbarInstance } from './utils';
88
export const Context = createContext();
99
Context.displayName = 'Rollbar';
1010

11-
const RollbarInstance = Symbol('RollbarInstance');
12-
const BaseOptions = Symbol('BaseOptions');
13-
const RollbarCtor = Symbol('RollbarCtor');
11+
export const RollbarInstance = Symbol('RollbarInstance');
12+
export const BaseOptions = Symbol('BaseOptions');
13+
export const RollbarCtor = Symbol('RollbarCtor');
1414

1515
export function getRollbarFromContext(context) {
1616
const { [RollbarInstance]: rollbar } = context;

0 commit comments

Comments
 (0)