Next.js · Middle · Question 7 of 75

Why can't you call cookies() inside a function with 'use cache'?

Explanation

If a cached function read cookies, one user's data could be served to another. The right way is to read cookies outside and pass the needed value as an argument (it becomes part of the key). For rare cases there's 'use cache: private', which doesn't store the result in the server cache across requests.

Further reading

Problem with a question

Next.js · Middle · question 7

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