Chapter 1 · Practice 2 of 5
Await params, searchParams, cookies and headers
Why it matters
Old tutorials read request data synchronously, and that code now breaks. Since Next.js 15, request APIs are asynchronous, and Next.js 16 removed the temporary synchronous access, so reading params.slug directly fails.
| API | Where | How to read it |
|---|---|---|
params, searchParams | pages, layouts, generateMetadata | const { slug } = await params |
cookies(), headers() | from next/headers | const store = await cookies() |
Use the generated PageProps<'/route'> and LayoutProps<'/route'> helpers to type them.
Avoid
- Reading
params.idwithout awaiting - Awaiting
paramsin a layout when only a nested component needs it