Skip to content

Commit

Permalink
typeof returns type name as string
Browse files Browse the repository at this point in the history
fix checking of window for SSR.
  • Loading branch information
PaulMaly committed Oct 15, 2019
1 parent 1c78bf5 commit 0b7d527
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import { writable } from 'svelte/store';
let prefix = 'svelteStore';

const get = (key) => {
if (typeof window === undefined || !localStorage) return undefined;
if (typeof window === 'undefined' || !window.localStorage) return;
const value = localStorage.getItem(key);
return value === undefined
? ""
: JSON.parse(value);
};

const set = (key, value) => {
if (typeof window === undefined || !localStorage) return;
if (typeof window === 'undefined' || !window.localStorage) return;

localStorage.setItem(key, JSON.stringify(value));
};
Expand All @@ -37,4 +37,4 @@ export const syncable = (name, value, hydrate = true) => {
}

return syncValue(key, writable(lastValue));
};
};

0 comments on commit 0b7d527

Please sign in to comment.