how can i use localStorage inside my client component? i get this error all the time
Unanswered
American Robin posted this in #help-forum
![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
American RobinOP
- error ReferenceError: localStorage is not defined
27 Replies
![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
American RobinOP
im storing data like: language in the localStorage
the component get pre rendered on the server right? if im not wrong, how do i have to work with this
![Avatar](https://cdn.discordapp.com/avatars/572329183334891520/3ea2e2e134a2327e2b8a7738876a17b5.webp?size=256)
fuma π joulev
Put it into
useEffect
![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
American RobinOP
oke ill try that
![Avatar](https://cdn.discordapp.com/avatars/572329183334891520/3ea2e2e134a2327e2b8a7738876a17b5.webp?size=256)
fuma π joulev
Your client component is pre-rendered on the server, but
useEffect
is only executed on the client side after hydration![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
American RobinOP
i dont get the error anymore, but its not workin properly atm
mhmm
atleast the error is gone
![Avatar](https://cdn.discordapp.com/avatars/572329183334891520/3ea2e2e134a2327e2b8a7738876a17b5.webp?size=256)
fuma π joulev
A flash is caused because the
useEffect
wonΓ’β¬β’t be executed instantly. It happens after hydration, you can add a skeleton to prevent the flash![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
American RobinOP
i would make a state, loading right?
to check if is loading true or not
and put the skell then there
![Avatar](https://cdn.discordapp.com/avatars/572329183334891520/3ea2e2e134a2327e2b8a7738876a17b5.webp?size=256)
fuma π joulev
Yeah, just determine yourself ![:RyoXD:](https://cdn.discordapp.com/emojis/1083042605761318943.png)
![:RyoXD:](https://cdn.discordapp.com/emojis/1083042605761318943.png)
![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
American RobinOP
oh it worked now
but as u said
there is still thhe "flash"
where it changes
after 1s
![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
American RobinOP
@fuma π joulev as i can see my custom hook is a problem
i cant use a custom hook with the local storage
![Avatar](https://cdn.discordapp.com/avatars/572329183334891520/3ea2e2e134a2327e2b8a7738876a17b5.webp?size=256)
fuma π joulev
What do you mean by custom hook?
ThatΓ’β¬β’s why you will need a skeleton component, so that the flash can look better for users
![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
American RobinOP
useLocalStorage hook
ye true
![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
American RobinOP
its only like rly 0.2ms ? smth like that rly instant, the skelton is showing only for that small time
is that ok tho?
![Avatar](https://cdn.discordapp.com/avatars/572329183334891520/3ea2e2e134a2327e2b8a7738876a17b5.webp?size=256)
fuma π joulev
Of course, itΓ’β¬β’s fine