0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Next.js15のparamsの処理(サーバーコンポーネント側)

Posted at

Next.js15に変更した後のparamsのコード

vercelを使用しようとしたら次のようなエラーが出た

エラー内容

Type error: Type '{ __tag__: "GET"; __param_position__: "second"; __param_type__: { params: Record<string, string | string[]>; }; }' does not satisfy the constraint 'ParamCheck<RouteContext>'.
  The types of '__param_type__.params' are incompatible between these types.
    Type 'Record<string, string | string[]>' is missing the following properties from type 'Promise<any>': then, catch, finally, [Symbol.toStringTag]

ここではparamsの型がPromise型にしないといけないというエラーが出ている

userIdを取得する例


```sample.tsx
export async function GET(
  req: Request,
  { params }: { params: Promise<Record<string, string>> }
) {
  const resolvedParams = await params; 
  const userId = resolvedParams.userId;

  <!-- 他の処理 -->

}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?