Next.js Discord

Discord Forum

Why code in `use client` component still execute in server

Answered
Entlebucher Mountain Dog posted this in #help-forum
Open in Discord
Entlebucher Mountain DogOP
I have a ClientComponent with use client, use sessionStorage inside it, but when run it throw error in server sessionStorage is not defined but the code still works well
so why it happens
Answered by Ray
because client component will be rendered on server and sessionStorage is not avaliable on server
View full answer

6 Replies

Answer
@Ray because client component will be rendered on server and sessionStorage is not avaliable on server
Entlebucher Mountain DogOP
thanks for the response, so how can I prevent this?
using dynamic import?
Entlebucher Mountain DogOP
I use sessionStorage (ss) to keep some information to keep some information that I use it on a form in difference screen later
Entlebucher Mountain DogOP
oh, I didn't put this in useEffect
forgot about this, thanks