Next.js · Middle · Question 7 of 75
Why can't you call cookies() inside a function with 'use cache'?
- ✓Correct answer: The cache is shared across requests, while cookies are per-request data
- 2
cookies()works only in client components - 3It's a restriction of development mode only
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.