using next/headers in a server component (not page or layout)
Unanswered
European sprat posted this in #help-forum
![Avatar](https://cdn.discordapp.com/embed/avatars/0.png)
European spratOP
my
the problem is no headers are found.
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
![Avatar](https://cdn.discordapp.com/avatars/642761688008884247/fcf7264431aeb83f3f4053834aea129c.webp?size=256)
Jaga Santagostino
headers function return an iterator if you want to log all the values use
to get a single value use
More info:
https://developer.mozilla.org/en-US/docs/Web/API/Headers/values
console.log(Object.fromEntries(headers().entries()));
to get a single value use
get
headers().get("my-header-name")
More info:
https://developer.mozilla.org/en-US/docs/Web/API/Headers/values
![Avatar](https://cdn.discordapp.com/embed/avatars/0.png)
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.
I did the same thing in middleware.ts and this worked. however, I don't want to use middleware for this case.
![Avatar](https://cdn.discordapp.com/embed/avatars/0.png)
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