# All files / link LinkProvider.tsx

100% Statements 43/43
100% Branches 3/3
100% Functions 2/2
100% Lines 43/43

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    441x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    544x
    544x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    61x
    61x
    61x
    61x
    61x
     import type { ForwardRefExoticComponent, ReactElement, ReactNode } from "react";
    import { createContext, useContext } from "react";
    import { Link } from "./Link";

    /**
     * @remarks \@since 6.0.0
     */
    export type CustomLinkComponent =
      | ForwardRefExoticComponent<{ href: string }>
      | ForwardRefExoticComponent<{ to: string }>
      | "a";

    const context = createContext<CustomLinkComponent>(Link);
    const { Provider } = context;
    context.displayName = "Link";

    /**
     * @remarks \@since 6.0.0
     */
    export function useLink(): CustomLinkComponent {
      return useContext(context);
    }

    /**
     * @remarks \@since 6.0.0
     */
    export interface LinkProviderProps {
      /**
       * @defaultValue `useLink() ?? Link`
       */
      value?: CustomLinkComponent;
      children: ReactNode;
    }

    /**
     * @remarks \@since 6.0.0
     */
    export function LinkProvider(props: LinkProviderProps): ReactElement {
      const { value, children } = props;
      const inherited = useLink();

      return <Provider value={value ?? inherited}>{children}</Provider>;
    }