UNPKG

@objectiv/plugin-react-router-tracked-components

Version:

React Router 6 automatically tracked Link and NavLink Components for Objectiv React Tracker

38 lines (34 loc) 1.79 kB
import { TrackedLinkContextObjectivProp } from '@objectiv/tracker-react'; import React from 'react'; import { LinkProps, NavLinkProps } from 'react-router-dom'; /** * An overridden version of TrackedLinkProps with a customized objectiv prop: * - No `objectiv.Component` attribute, as it's hard-coded to Link * - No `objectiv.href` attribute, as we can retrieve one automatically via the `useHref` hook * - The objectiv prop itself is optional as there are no required attributes left */ declare type TrackedLinkProps = LinkProps & { objectiv?: Omit<TrackedLinkContextObjectivProp, 'Component' | 'href'>; }; /** * Wraps Link in a TrackedLinkContext which automatically instruments tracking PressEvent on click. */ declare const TrackedLink: React.ForwardRefExoticComponent<LinkProps & { objectiv?: Omit<TrackedLinkContextObjectivProp, "href" | "Component"> | undefined; } & React.RefAttributes<HTMLAnchorElement>>; /** * An overridden version of TrackedLinkProps with a customized objectiv prop: * - No `objectiv.Component` attribute, as it's hard-coded to NavLink * - No `objectiv.href` attribute, as we can retrieve one automatically via the `useHref` hook * - The objectiv prop itself is optional as there are no required attributes left */ declare type TrackedNavLinkProps = NavLinkProps & { objectiv?: Omit<TrackedLinkContextObjectivProp, 'Component' | 'href'>; }; /** * Wraps NavLink in a LinkContext and automatically instruments tracking PressEvent on click. */ declare const TrackedNavLink: React.ForwardRefExoticComponent<NavLinkProps & { objectiv?: Omit<TrackedLinkContextObjectivProp, "href" | "Component"> | undefined; } & React.RefAttributes<HTMLAnchorElement>>; export { TrackedLink, TrackedLinkProps, TrackedNavLink, TrackedNavLinkProps };