Next.js Discord

Discord Forum

params.id

Answered
Encyrtid wasp posted this in #help-forum
Open in Discord
Encyrtid waspOP
Route "/api/products/[id]" used params.id. params should be awaited before using its properties.

hi,is anyone familiar with this error?
i got this error on console when making http request but the code still works fine,
why is that?and how do i fix this?
Answered by Yi Lon Ma
-{params}: {params: {id:string}}
+{params}:{params:Promise<{id:string}>}
View full answer

7 Replies

const id = (await params).id
Encyrtid waspOP
is this wrong?

export async function GET(
req: Request,
{ params }: { params: { id: string } }
) {
const product = await prisma.product.findUnique({
where: { id: Number(params.id) },
});
this line is where i get the error?
yes
-{params}: {params: {id:string}}
+{params}:{params:Promise<{id:string}>}
Answer
@Yi Lon Ma diff -{params}: {params: {id:string}} +{params}:{params:Promise<{id:string}>}
Encyrtid waspOP
wow,the error's gone...
Thank you...