@rollbar/react
Version:
Effortlessly track and debug errors in your React applications with Rollbar. This package includes advanced error tracking features and a set of React-specific enhancements to help you identify and fix issues more quickly.
36 lines (32 loc) • 1.14 kB
JavaScript
"use client";
import invariant from './external/tiny-invariant/dist/esm/tiny-invariant.js';
import { useLayoutEffect, useEffect } from 'react';
import { useRollbar } from './useRollbar.js';
// Simple version does its job
// export function useRollbarContext(context) {
// useRollbarConfiguration({ payload: { context }});
// }
// Complex version will set the context when part of the tree and reset back to original context when removed
function useRollbarContext() {
var ctx = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
var isLayout = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
invariant(typeof ctx === 'string', '`ctx` must be a string');
var rollbar = useRollbar();
(isLayout ? useLayoutEffect : useEffect)(function () {
var origCtx = rollbar.options.payload.context;
rollbar.configure({
payload: {
context: ctx
}
});
return function () {
rollbar.configure({
payload: {
context: origCtx
}
});
};
}, [ctx]);
}
export { useRollbarContext };
//# sourceMappingURL=useRollbarContext.js.map