UNPKG

916 BJavaScriptView Raw
1"use strict";
2
3require("core-js/modules/es.object.define-property");
4
5Object.defineProperty(exports, "__esModule", {
6 value: true
7});
8exports["default"] = useTracking;
9
10var _react = require("react");
11
12var _withTrackingComponentDecorator = require("./withTrackingComponentDecorator");
13
14function useTracking() {
15 var trackingContext = (0, _react.useContext)(_withTrackingComponentDecorator.ReactTrackingContext);
16
17 if (!(trackingContext && trackingContext.tracking)) {
18 throw new Error('Attempting to call `useTracking` ' + 'without a ReactTrackingContext present. Did you forget to wrap the top of ' + 'your component tree with `track`?');
19 }
20
21 return (0, _react.useMemo)(function () {
22 return {
23 getTrackingData: trackingContext.tracking.getTrackingData,
24 trackEvent: trackingContext.tracking.dispatch
25 };
26 }, [trackingContext.tracking.getTrackingData, trackingContext.tracking.dispatch]);
27}
\No newline at end of file