0

for my SSG page I need to pass a parameter which is language to my api call function which is inside generateStaticParams function, I have stored language inside cookies and I can not access that, is there a way I can pass params to my function?

export async function generateStaticParams() {
  const getAllCategories = await getCategories(); // this needs language
  return getAllCategories.map((category: Category) => ({
    id: category.id,
    category: category.groupName,
  }));
}

Radmehr
  • 299
  • 2
  • 12
EshgheCode
  • 288
  • 4
  • 19

1 Answers1

0

You can use cookies with Nextjs official lib in Next13

import { cookies } from 'next/headers';

export async function generateStaticParams() {

    const cookieStore = cookies();
    const language = cookieStore.get('language');

    const getAllCategories = await getCategories(language); // this needs language
    return getAllCategories.map((category: Category) => ({
        id: category.id,
        category: category.groupName,
    }));
}
Radmehr
  • 299
  • 2
  • 12