examples: improve typings for i18n app dir (#60160)

This commit is contained in:
Nicolas Froidure 2024-01-03 15:42:12 +01:00 committed by GitHub
parent 7818c2d736
commit 2d52962dfd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 8 deletions

View file

@ -1,14 +1,12 @@
'use client'
import { useState } from 'react'
import { type getDictionary } from '../../../get-dictionary'
export default function Counter({
dictionary,
}: {
dictionary: {
increment: string
decrement: string
}
dictionary: Awaited<ReturnType<typeof getDictionary>>['counter']
}) {
const [count, setCount] = useState(0)
return (

View file

@ -2,11 +2,11 @@
import { usePathname } from 'next/navigation'
import Link from 'next/link'
import { i18n } from '../../../i18n-config'
import { i18n, type Locale } from '../../../i18n-config'
export default function LocaleSwitcher() {
const pathName = usePathname()
const redirectedPathName = (locale: string) => {
const redirectedPathName = (locale: Locale) => {
if (!pathName) return '/'
const segments = pathName.split('/')
segments[1] = locale

View file

@ -1,4 +1,4 @@
import { i18n } from '../../i18n-config'
import { i18n, type Locale } from '../../i18n-config'
export async function generateStaticParams() {
return i18n.locales.map((locale) => ({ lang: locale }))
@ -9,7 +9,7 @@ export default function Root({
params,
}: {
children: React.ReactNode
params: { lang: string }
params: { lang: Locale }
}) {
return (
<html lang={params.lang}>