From fd5380a812e265c6e0e42750c434297695c69c2d Mon Sep 17 00:00:00 2001 From: Christel Westerberg Date: Wed, 28 Aug 2024 15:41:25 +0200 Subject: [PATCH] fix: move useLazyPathname to hooks dir --- components/Current/Header/LoginButton.tsx | 2 +- hooks/useLazyPathname.ts | 16 ++++++++++++++++ utils/url.ts | 16 ---------------- 3 files changed, 17 insertions(+), 17 deletions(-) create mode 100644 hooks/useLazyPathname.ts diff --git a/components/Current/Header/LoginButton.tsx b/components/Current/Header/LoginButton.tsx index 86b66400f..d74d63e80 100644 --- a/components/Current/Header/LoginButton.tsx +++ b/components/Current/Header/LoginButton.tsx @@ -7,8 +7,8 @@ import { login } from "@/constants/routes/handleAuth" import Link from "@/components/TempDesignSystem/Link" import { LinkProps } from "@/components/TempDesignSystem/Link/link" import useLang from "@/hooks/useLang" +import { useLazyPathname } from "@/hooks/useLazyPathname" import { trackLoginClick } from "@/utils/tracking" -import { useLazyPathname } from "@/utils/url" import { TrackingPosition } from "@/types/components/tracking" diff --git a/hooks/useLazyPathname.ts b/hooks/useLazyPathname.ts new file mode 100644 index 000000000..5f3a53c18 --- /dev/null +++ b/hooks/useLazyPathname.ts @@ -0,0 +1,16 @@ +"use client" +import { usePathname } from "next/navigation" +import { useEffect, useState } from "react" + +/*** This hook is used to get the current pathname (as reflected in window.location.href) of the page. During ssr, the value from usePathname() + * is the value return from NextResponse.rewrite() (e.g. the path from the app directory) instead of the actual pathname from the URL. + */ +export function useLazyPathname() { + const pathName = usePathname() + const [updatedPathName, setUpdatedPathName] = useState(null) + + useEffect(() => { + setUpdatedPathName(pathName) + }, [pathName]) + return updatedPathName ? updatedPathName : null +} diff --git a/utils/url.ts b/utils/url.ts index d33f8a7a8..51ba2c52d 100644 --- a/utils/url.ts +++ b/utils/url.ts @@ -1,6 +1,3 @@ -import { usePathname } from "next/navigation" -import { useEffect, useState } from "react" - export function removeMultipleSlashes(str: string) { return str.replaceAll(/\/\/+/g, "/") } @@ -12,16 +9,3 @@ export function removeTrailingSlash(pathname: string) { } return pathname } - -/*** This hook is used to get the current pathname (as reflected in window.location.href) of the page. During ssr, the value from usePathname() - * is the value return from NextResponse.rewrite() (e.g. the path from the app directory) instead of the actual pathname from the URL. - */ -export function useLazyPathname() { - const pathName = usePathname() - const [updatedPathName, setUpdatedPathName] = useState(null) - - useEffect(() => { - setUpdatedPathName(pathName) - }, [pathName]) - return updatedPathName ? updatedPathName : null -}