examples: improve typings for i18n app dir (#60160)
This commit is contained in:
parent
7818c2d736
commit
2d52962dfd
3 changed files with 6 additions and 8 deletions
|
@ -1,14 +1,12 @@
|
||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import { useState } from 'react'
|
import { useState } from 'react'
|
||||||
|
import { type getDictionary } from '../../../get-dictionary'
|
||||||
|
|
||||||
export default function Counter({
|
export default function Counter({
|
||||||
dictionary,
|
dictionary,
|
||||||
}: {
|
}: {
|
||||||
dictionary: {
|
dictionary: Awaited<ReturnType<typeof getDictionary>>['counter']
|
||||||
increment: string
|
|
||||||
decrement: string
|
|
||||||
}
|
|
||||||
}) {
|
}) {
|
||||||
const [count, setCount] = useState(0)
|
const [count, setCount] = useState(0)
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -2,11 +2,11 @@
|
||||||
|
|
||||||
import { usePathname } from 'next/navigation'
|
import { usePathname } from 'next/navigation'
|
||||||
import Link from 'next/link'
|
import Link from 'next/link'
|
||||||
import { i18n } from '../../../i18n-config'
|
import { i18n, type Locale } from '../../../i18n-config'
|
||||||
|
|
||||||
export default function LocaleSwitcher() {
|
export default function LocaleSwitcher() {
|
||||||
const pathName = usePathname()
|
const pathName = usePathname()
|
||||||
const redirectedPathName = (locale: string) => {
|
const redirectedPathName = (locale: Locale) => {
|
||||||
if (!pathName) return '/'
|
if (!pathName) return '/'
|
||||||
const segments = pathName.split('/')
|
const segments = pathName.split('/')
|
||||||
segments[1] = locale
|
segments[1] = locale
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { i18n } from '../../i18n-config'
|
import { i18n, type Locale } from '../../i18n-config'
|
||||||
|
|
||||||
export async function generateStaticParams() {
|
export async function generateStaticParams() {
|
||||||
return i18n.locales.map((locale) => ({ lang: locale }))
|
return i18n.locales.map((locale) => ({ lang: locale }))
|
||||||
|
@ -9,7 +9,7 @@ export default function Root({
|
||||||
params,
|
params,
|
||||||
}: {
|
}: {
|
||||||
children: React.ReactNode
|
children: React.ReactNode
|
||||||
params: { lang: string }
|
params: { lang: Locale }
|
||||||
}) {
|
}) {
|
||||||
return (
|
return (
|
||||||
<html lang={params.lang}>
|
<html lang={params.lang}>
|
||||||
|
|
Loading…
Reference in a new issue