#nextjs blog wrong

2 messages · Page 1 of 1 (latest)

calm orbit
#

export async function getStaticProps(context) {
const id = context.params.id
const posts = await client.fetch(groq
*[_type == "post" && slug.current == $id][0] )
return{
props:{posts}
}
}
where did I make wrong actually I dont know what should am I do ?

gloomy radish
# calm orbit export async function getStaticProps(context) { const id = context.params.id ...

It looks like you are trying to use a query parameter?

from https://nextjs.org/docs/basic-features/data-fetching/get-static-props :

"getStaticProps does not have access to the incoming request (such as query parameters or HTTP headers) as it generates static HTML. "

Fetch data and generate static pages with getStaticProps. Learn more about this API for data fetching in Next.js.