From 51cef9f53c0d9e1268eb441c6e116f7ca30f0818 Mon Sep 17 00:00:00 2001 From: Simon Knittel Date: Mon, 6 Jan 2025 16:27:21 +0100 Subject: [PATCH] refactor: use prefetch attribute instead of router.prefetch() --- app/src/common/components/Link.tsx | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/app/src/common/components/Link.tsx b/app/src/common/components/Link.tsx index 90cb8d97..26c0f82a 100644 --- a/app/src/common/components/Link.tsx +++ b/app/src/common/components/Link.tsx @@ -1,27 +1,23 @@ "use client"; import NextLink from "next/link"; -import { useRouter } from "next/navigation"; -import type { ComponentProps } from "react"; +import { useState, type ComponentProps } from "react"; type Props = ComponentProps; export const Link = (props: Props) => { - const { prefetch, href, onMouseEnter, ...rest } = props; - const router = useRouter(); + const { prefetch, onMouseEnter, ...rest } = props; + + const [_prefetch, setPrefetch] = useState( + prefetch === undefined ? false : prefetch, + ); - const _prefetch = prefetch === undefined ? false : prefetch; const _onMouseEnter = prefetch === undefined && onMouseEnter === undefined - ? () => router.prefetch(typeof href === "string" ? href : href.href) + ? () => setPrefetch(true) : onMouseEnter; return ( - + ); };