@atlaskit/analytics-next
Version:
React components, HOCs and hooks to assist with tracking user activity with React components
23 lines • 1.03 kB
JavaScript
import _extends from "@babel/runtime/helpers/extends";
import React, { forwardRef } from 'react';
import { useAnalyticsEvents } from '../hooks/useAnalyticsEvents';
import { usePatchedProps } from '../hooks/usePatchedProps';
const withAnalyticsEvents = (createEventMap = {}) => WrappedComponent => {
const WithAnalyticsEvents = /*#__PURE__*/forwardRef((props, ref) => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore: to unblock React 18.2.0 -> 18.3.1 version bump in Jira
const {
patchedEventProps
} = usePatchedProps(createEventMap, props);
const {
createAnalyticsEvent
} = useAnalyticsEvents();
return /*#__PURE__*/React.createElement(WrappedComponent, _extends({}, props, patchedEventProps, {
createAnalyticsEvent: createAnalyticsEvent,
ref: ref
}));
});
WithAnalyticsEvents.displayName = `WithAnalyticsEvents(${WrappedComponent.displayName || WrappedComponent.name})`;
return WithAnalyticsEvents;
};
export default withAnalyticsEvents;