Skip to content

Instantly share code, notes, and snippets.

@SidKH
Created September 3, 2025 15:27
Show Gist options
  • Select an option

  • Save SidKH/cd3b592091f81cbabf3207dffdf7d685 to your computer and use it in GitHub Desktop.

Select an option

Save SidKH/cd3b592091f81cbabf3207dffdf7d685 to your computer and use it in GitHub Desktop.
# Async request APIs
APIs that rely on request specific data (headers, cookies, params, and searchParams) are async
Example:
```tsx
import { headers, cookies } from "next/headers";
type Params = Promise<{ slug: string }>;
type SearchParams = Promise<{
[key: string]: string | string[] | undefined;
}>;
export default async function Page({
params,
searchParams,
}: {
params: Params;
searchParams: SearchParams;
}) {
const params = await props.params;
const searchParams = await props.searchParams;
const slug = params.slug;
const query = searchParams.query;
const headersList = await headers();
const userAgent = headersList.get("user-agent");
const cookieStore = await cookies();
const token = cookieStore.get("token");
return (
/* */
);
}
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment