opral / inlang-paraglide-js

Tree-shakable i18n library build on the inlang ecosystem.
https://inlang.com/m/gerre34r/library-inlang-paraglideJs
42 stars 0 forks source link

Incorrect usePathname Hook Usage in Language Switcher Guide #17

Closed PrennerProducts closed 6 months ago

PrennerProducts commented 6 months ago

Hello,

I've encountered an issue in the Building a Language Switcher section of the guide for integrating useParaglideJsWithNextjsAppRouter. The example provided for the LanguageSwitcher component seems to misinterpret the value returned by the usePathname hook.

Current Implementation:

import { Link, usePathname } from "@/lib/i18n"

export default function LanguageSwitcher() {
    const { pathname } = usePathname();
    return (
        <div>
            <Link href={pathname} locale="en">English</Link>
            <Link href={pathname} locale="de">Deutsch</Link>
        </div>
    );
}

Issue: The usePathname hook is expected to return a string representing the current pathname. However, the current guide's syntax { pathname } = usePathname() implies that it returns an object with a pathname property, which is incorrect.

Expected Correction: The correct usage should directly assign the string returned by usePathname to a pathname variable like so:

import { Link, usePathname } from "@/lib/i18n"

export default function LanguageSwitcher() {
    const pathname = usePathname();
    return (
        <div>
            <Link href={pathname} locale="en">English</Link>
            <Link href={pathname} locale="de">Deutsch</Link>
        </div>
    );
}

With this correction, the pathname variable will correctly store the string value representing the current path, and the Link component can function as intended.

I believe updating the guide with the correct usage can prevent confusion for future readers. Thank you for looking into this issue.

cheers

linear[bot] commented 6 months ago

PARJS-23 Incorrect usePathname Hook Usage in Language Switcher Guide

LorisSigrist commented 6 months ago

Good catch! Thank you, I'll correct that.

LorisSigrist commented 6 months ago

Fixed in https://github.com/opral/monorepo/commit/692b166bfb966b8199d648c9954811434623a1c1