Understand and correctly implement the asynchronous behavior of Next.js APIs and components. Follow these guidelines:
1. Add `
Understand and correctly implement the asynchronous behavior of Next.js APIs and components. Follow these guidelines:
<Suspense>
boundaries around components that use hooks that can trigger suspense, such as useSearchParams
in the Next.js App Router:<Suspense>
<ComponentUsingSearchParams />
</Suspense>
cookies()
from ‘next/headers’ returns a synchronous object:// Incorrect
const cookieStore = await cookies();
// Correct
const cookieStore = cookies();
searchParams
are regular objects, not Promises - handle them correctly:// Incorrect
export default async function Page(props: {
searchParams: Promise<{ param?: string }>;
}) {
const searchParams = await props.searchParams;
// ...
}
// Correct
export default async function Page({
searchParams
}: {
searchParams: { param?: string };
}) {
// ...
}
Correctly identifying when to use asynchronous patterns like Suspense
and await
improves application stability and performance.
Enter the URL of a public GitHub repository