Skip to content

Is it possible to use persisted data from localStorage? #1202

Closed Answered by hollandThomas
jvnm-dev asked this question in Q&A
Discussion options

You must be logged in to vote

When server-side-rendering, your code is executed in a JS environment that is not a browser (typically Node.js or Deno or Cloudflare Workers or ...). In particular, those environments do not have access to browser-only APIs such as localStorage.

What you need to do is to wrap your calls to browser-only APIs in useEffects. Remix has an example in their docs
https://remix.run/docs/en/v1/guides/constraints#rendering-with-browser-only-apis

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@hollandThomas
Comment options

Answer selected by jvnm-dev
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants