Skip to content

How to use window.localStorage with prerender #954

Answered by rschristian
PrettyCoffee asked this question in Q&A
Discussion options

You must be logged in to vote

window is not accessible in Node, where prerendering happens. You'll need to use a window check/guard:

if (typeof window !== 'undefined') {
    window.localStorage.setItem("key", value);
}

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@PrettyCoffee
Comment options

@rschristian
Comment options

Answer selected by PrettyCoffee
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