get params for generateStaticParams
Unanswered
Barbary Lion posted this in #help-forum
Barbary LionOP
How can I get params on generateStaticParams function?
I need this params to be used on the body of the api.
this api call will be on generateStaticParams
like this
export async function generateStaticParams({
}: {
}) {
const response = await getClientProjectApi({
"vendor_squad_id": '29155329-67ac-4e4e-981f-c2df40a9d3a3', --> this static squad id as of now but here I want to get squad id
"user_id": "Xq1VU2vUJ0XDKxKsGVZhdNb1V3b2",
"sort_by": "newest_first",
"search": ""
});
return response.allProjects?.data?.map((project: any) => ({
projectid: project["project_id"],
workid: project["work_id"]
}))
}
I need this params to be used on the body of the api.
this api call will be on generateStaticParams
like this
export async function generateStaticParams({
}: {
}) {
const response = await getClientProjectApi({
"vendor_squad_id": '29155329-67ac-4e4e-981f-c2df40a9d3a3', --> this static squad id as of now but here I want to get squad id
"user_id": "Xq1VU2vUJ0XDKxKsGVZhdNb1V3b2",
"sort_by": "newest_first",
"search": ""
});
return response.allProjects?.data?.map((project: any) => ({
projectid: project["project_id"],
workid: project["work_id"]
}))
}
2 Replies
you can access them directly inside the generate static params. The function gets the same variables as the page gets:
// app/products/[category]/[product]/page.tsx
// Generate segments for [product] using the `params` passed from
// the parent segment's `generateStaticParams` function
export async function generateStaticParams({
params: { category },
}: {
params: { category: string }
}) {
const products = await fetch(
`https://.../products?category=${category}`
).then((res) => res.json())
return products.map((product) => ({
product: product.id,
}))
}
export default function Page({
params,
}: {
params: { category: string; product: string }
}) {
// ...
}
@Barbary Lion solved?