Next.js · Middle · Question 57 of 75
Why can't you call (await cookies()).set(...) while rendering a server component?
- ✓Correct answer: Cookies can be set only in Server Actions, Route Handlers or
proxy.ts- headers may already be streaming during render - 2
cookies()is read-only everywhere - 3Setting cookies requires a client component
Explanation
HTTP headers must be sent before the body. Render may stream, so Next.js only allows writing cookies where the response is fully controlled.