| 1 | # Async Patterns |
| 2 | |
| 3 | In Next.js 15+, `params`, `searchParams`, ` |
| 4 | |
| 5 | ## Async Params and SearchParams |
| 6 | |
| 7 | Always type them as `Promise<...>` and await them. |
| 8 | |
| 9 | ### Pages and Layouts |
| 10 | |
| 11 | ```tsx |
| 12 | type Props |
| 13 | |
| 14 | export default async function |
| 15 | const { slug |
| 16 | } |
| 17 | ``` |
| 18 | |
| 19 | ### Route Handlers |
| 20 | |
| 21 | ```tsx |
| 22 | export async function GET |
| 23 | const { id |
| 24 | } |
| 25 | ``` |
| 26 | |
| 27 | ### SearchParams |
| 28 | |
| 29 | ```tsx |
| 30 | type Props |
| 31 | params: Promise |
| 32 | searchParams: Promise |
| 33 | }; |
| 34 | |
| 35 | export default async function |
| 36 | const { slug |
| 37 | const { query |
| 38 | } |
| 39 | ``` |
| 40 | |
| 41 | ### Synchronous Components |
| 42 | |
| 43 | Use `React.use()` for non-async components: |
| 44 | |
| 45 | ```tsx |
| 46 | import { use } |
| 47 | |
| 48 | type Props |
| 49 | |
| 50 | export default function Page |
| 51 | const { slug |
| 52 | } |
| 53 | ``` |
| 54 | |
| 55 | ### generateMetadata |
| 56 | |
| 57 | ```tsx |
| 58 | type Props |
| 59 | |
| 60 | export async function generateMetadata |
| 61 | const { slug |
| 62 | return { title: |
| 63 | } |
| 64 | ``` |
| 65 | |
| 66 | ## Async Cookies and Headers |
| 67 | |
| 68 | ```tsx |
| 69 | import { cookies, headers |
| 70 | |
| 71 | export default async function |
| 72 | const cookieStore = |
| 73 | const headersList = |
| 74 | |
| 75 | const theme = |
| 76 | const userAgent = |
| 77 | } |
| 78 | ``` |
| 79 | |
| 80 | ## Migration Codemod |
| 81 | |
| 82 | ```bash |
| 83 | npx @next/codemod@latest next-async-request-api . |
| 84 | ``` |