Next.js Discord

Discord Forum

(i18n) Do I need to set component signature in a specific way to receive lang as a param?

Answered
Satin Angora posted this in #help-forum
Open in Discord
Satin AngoraOP
NextJS shows this signature to receive lang as a parameter
export default async function IndexPage({
  params: { lang },
}: {
  params: { lang: Locale }
}) {...
when using Middleware to use i18n where the special files are under the path /app/[lang]/.

Considering there may be different properties too, I was wondering can I tidy it up using interfaces? Does it need to be written this way?
Answered by joulev
yes you can use the type as any normal typescript type. it can be like you wrote, it can also be
interface IndexPageParams {
  lang: Locale
}
export default async function IndexPage({
  params: { lang },
}: {
  params: IndexPageParams
}) {}

and it can also be any different and valid way to declare typescript types
View full answer

1 Reply

@Satin Angora _NextJS_ shows this signature to receive `lang` as a parameter tsx export default async function IndexPage({ params: { lang }, }: { params: { lang: Locale } }) {... when using `Middleware` to use i18n where the special files are under the path `/app/[lang]/`. Considering there may be different properties too, I was wondering can I tidy it up using `interface`s? Does it need to be written this way?
yes you can use the type as any normal typescript type. it can be like you wrote, it can also be
interface IndexPageParams {
  lang: Locale
}
export default async function IndexPage({
  params: { lang },
}: {
  params: IndexPageParams
}) {}

and it can also be any different and valid way to declare typescript types
Answer