mirror of
https://github.com/hanzoai/sentinel.git
synced 2026-09-29 22:34:33 +00:00
26 lines
915 B
TypeScript
26 lines
915 B
TypeScript
import {useContext} from 'react';
|
|
|
|
import getDisplayName from 'sentry/utils/getDisplayName';
|
|
import {RouteAnalyticsContext} from 'sentry/views/routeAnalyticsContextProvider';
|
|
|
|
type WithRouteAnalyticsProps = React.ContextType<typeof RouteAnalyticsContext>;
|
|
|
|
type WrappedProps<P> = Omit<P, keyof WithRouteAnalyticsProps> &
|
|
Partial<WithRouteAnalyticsProps>;
|
|
|
|
const withRouteAnalytics = <P extends WithRouteAnalyticsProps>(
|
|
WrappedComponent: React.ComponentType<P>
|
|
) => {
|
|
function ComponentWithRouteAnalytics(props: WrappedProps<P>) {
|
|
const routeAnalyticsContext = useContext(RouteAnalyticsContext);
|
|
return <WrappedComponent {...(props as P)} {...routeAnalyticsContext} />;
|
|
}
|
|
ComponentWithRouteAnalytics.displayName = `withRouteAnalytics(${getDisplayName(
|
|
WrappedComponent
|
|
)})`;
|
|
return ComponentWithRouteAnalytics;
|
|
};
|
|
|
|
export default withRouteAnalytics;
|
|
export type {WithRouteAnalyticsProps};
|