Next.js Discord

Discord Forum

Using localStorage or/and cookies in server side component

Answered
Pond loach posted this in #help-forum
Open in Discord
Pond loachOP
How am i able to get localStorage and cookies from client side in the server side component?
Answered by B33fb0n3
something in your message does not match... a server component is rendered on the server and not on the client side.

The server does not know any localstorage, because it's local. So inside the browser of the user. And that means: only clientside. You can access it via localStorage.#

The cookies can be access using nextjs only though server components like cookies().#. Of course you can also access the them clientside via third party libraries
View full answer

4 Replies

@Pond loach How am i able to get localStorage and cookies from client side in the server side component?
something in your message does not match... a server component is rendered on the server and not on the client side.

The server does not know any localstorage, because it's local. So inside the browser of the user. And that means: only clientside. You can access it via localStorage.#

The cookies can be access using nextjs only though server components like cookies().#. Of course you can also access the them clientside via third party libraries
Answer
@Pond loach solved?
@B33fb0n3 <@655679234026504202> solved?
Pond loachOP
Yes sir
happy to help