Hello guys.
First of all, please apologize my english, I'm from France !
I found this bit of code because I need to create the route handlers.
=========================================
import { prisma } from "@/lib/prisma";
import { NextResponse } from "next/server";
export async function GET(
request: Request,
{ params }: { params: { id: string } }
) {
const id = params.id;
const user = await prisma.user.findUnique({
where: {
id,
},
});
if (!user) {
return new NextResponse("No user with ID found", { status: 404 });
}
return NextResponse.json(user);
}
============================
It's in Typescript and I'm learning it since few days only :
I don't understand the second parameter of the GET function :
{ params } : { params: { id: string }
I know that we need the ID of the user we want to get. But I don't know why we just simply put something like that :
{ params } : { id : string }
Can somebody help me to understand please 🙂
Thanks a lot everybody !