Next.js · Middle · Question 57 of 75

Why can't you call (await cookies()).set(...) while rendering a server 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.

Further reading

Problem with a question

Next.js · Middle · question 57

Test yourself

Take the Next.js · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz