DEV Community

Discussion on: 🚀 Svelte Quick Tip: Connect a store to local storage

Collapse
 
lubiah profile image
Lucretius Biah

In sveltekit, you can check if the piece of code is running on the server or browser, you just have to import the browser variable from the env and then use an if statement to run your code. So it should be something like this

import { browser } from "$app/env";


if (browser){
    variable.subscribe((value) => localStorage.user = JSON.stringify(value))
}
Enter fullscreen mode Exit fullscreen mode
Collapse
 
cepiherd profile image
cepiherd

this code is running in my code , thank you ,appreciated