/** * > [!NOTE] * > Install using `bunx shadcn@latest add @remix-utils/use-delegated-anchors`. * * When using Remix, you can use the `` component to navigate between pages. However, if you have a `` that links to a page in your app, it will cause a full page refresh. This can be what you want, but sometimes you want to use client-side navigation here instead. * * The `useDelegatedAnchors` hook lets you add client-side navigation to anchor tags in a portion of your app. This can be specially useful when working with dynamic content like HTML or Markdown from a CMS. * * ```tsx * import { useDelegatedAnchors } from "remix-utils/use-delegated-anchors"; * * export async function loader() { * let content = await fetchContentFromCMS(); * return json({ content }); * } * * export default function Component() { * let { content } = useLoaderData(); * * let ref = useRef(null); * useDelegatedAnchors(ref); * * return
; * } * ``` * * --- * * * > [!NOTE] * > Install using `bunx shadcn@latest add @remix-utils/use-delegated-anchors`. * * If additionally you want to be able to prefetch your anchors you can use the `PrefetchPageAnchors` components. * * This components wraps your content with anchors inside, it detects any hovered anchor to prefetch it, and it delegates them to Remix. * * ```tsx * import { PrefetchPageAnchors } from "remix-utils/use-delegated-anchors"; * * export async function loader() { * let content = await fetchContentFromCMS(); * return json({ content }); * } * * export default function Component() { * let { content } = useLoaderData(); * * return ( * *
* * ); * } * ``` * * Now you can see in your DevTools that when the user hovers an anchor it will prefetch it, and when the user clicks it will do a client-side navigation. * * @author [Sergio Xalambrí](https://sergiodxa.com) * @module Hook/Use Delegated Anchors */ import * as React from "react"; export declare function isLinkEvent(event: MouseEvent): HTMLAnchorElement | undefined; export declare function useDelegatedAnchors(nodeRef: React.RefObject): void; export declare function PrefetchPageAnchors({ children }: { children: React.ReactNode; }): import("react/jsx-runtime").JSX.Element;