Next.js · Middle · Question 20 of 75
How do you read a cookie in a Next.js 16 server component?
- ✓Correct answer:
const store = await cookies(); store.get('theme') - 2
document.cookieinside the server component - 3
const theme = cookies().get('theme')withoutawait
Explanation
cookies() and headers() are async: synchronous access was removed in Next.js 16. Using them makes rendering request-dependent. You can set cookies in Server Actions and Route Handlers, but not while rendering a server component.