Skip to content

Commit

Permalink
add Link component example for easy <a> linking
Browse files Browse the repository at this point in the history
  • Loading branch information
KishiTheMechanic committed Oct 30, 2024
1 parent 0a1abf3 commit cd12e83
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,28 @@ export function useLocale() {
}
```

```tsx:./components/utils/Link.tsx
import { useLocale } from '@/hooks/i18n/useLocale.ts'
import { JSX } from 'preact'

interface LinkProps extends JSX.HTMLAttributes<HTMLAnchorElement> {
href: string
children: preact.ComponentChildren
}

export default function Link({ href, children, ...props }: LinkProps) {
const locale = useLocale()

const localizedHref = `/${locale}${href}`

return (
<a href={localizedHref} {...props}>
{children}
</a>
)
}
```

##### Usage

```tsx
Expand Down
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@elsoul/fresh-i18n",
"version": "1.1.0",
"version": "1.1.1",
"description": "A simple and flexible internationalization (i18n) plugin for Deno's Fresh framework.",
"runtimes": ["deno", "browser"],
"exports": "./mod.ts",
Expand Down

0 comments on commit cd12e83

Please sign in to comment.