Next.js Discord

Discord Forum

using next/headers in a server component (not page or layout)

European sprat posted this in #help-forum
Open in Discord
European spratOP
my layout.tsx is importing a server component Footer.tsx

Footer is importing headers from next/headers

the problem is no headers are found.

Footer snippet:
const FooterInner = ({ dict, lng }: Props) => {
 // const headerStore = headers();

 // console.log("FooterInner -- headerStore.values()", headerStore.values()); <======= This should log headers

  return (

3 Replies

Jaga Santagostino
headers function return an iterator if you want to log all the values use

to get a single value use get

More info:
European spratOP
thanks @Jaga Santagostino I tried to do that as well and still received a blank object.

I did the same thing in middleware.ts and this worked. however, I don't want to use middleware for this case.
Asian black bear
Have you tried accessing a specific header directly? Because iterating and trying to log all of them is an uncommon and unrealistic usecase to begin with