foxact
Version:
React Hooks/Utils done right. For browser, SSR, and React Server Components.
32 lines (29 loc) • 1.49 kB
TypeScript
import { LinkProps } from 'next/link';
interface UrlObject {
auth?: string | null | undefined;
hash?: string | null | undefined;
host?: string | null | undefined;
hostname?: string | null | undefined;
href?: string | null | undefined;
pathname?: string | null | undefined;
protocol?: string | null | undefined;
search?: string | null | undefined;
slashes?: boolean | null | undefined;
port?: string | number | null | undefined;
query?: any;
}
interface UseNextLinkOptions extends Omit<LinkProps, 'as' | 'href' | 'legacyBehavior' | 'shallow' | 'passHref' | 'locale'> {
ref?: React.RefObject<HTMLAnchorElement> | React.RefCallback<HTMLAnchorElement> | null;
}
interface UseNextLinkReturnProps extends Partial<React.JSX.IntrinsicElements['a']> {
ref: React.RefCallback<HTMLAnchorElement>;
onTouchStart: React.TouchEventHandler<HTMLAnchorElement>;
onMouseEnter: React.MouseEventHandler<HTMLAnchorElement>;
onClick: React.MouseEventHandler<HTMLAnchorElement>;
href?: string;
}
/** @see https://foxact.skk.moe/use-next-link */
declare function useNextLink(hrefProp: string | UrlObject, { prefetch: prefetchProp, ref, onClick, onMouseEnter, onTouchStart, scroll: routerScroll, replace, ...restProps }: UseNextLinkOptions): [isPending: boolean, linkProps: UseNextLinkReturnProps];
declare const unstable_useNextLink: typeof useNextLink;
export { unstable_useNextLink };
export type { UseNextLinkOptions, UseNextLinkReturnProps };