Skip to content

Commit

Permalink
Merge pull request #1 from pixeleet/fix/unparsed-on-load
Browse files Browse the repository at this point in the history
Fix cookie not being parsed on load.
  • Loading branch information
eXon committed Apr 19, 2015
2 parents 3b1780c + 877e9a5 commit 45a62ad
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@ function load(name) {

function save(name, val, opt) {
_cookies[name] = val;

// Cookies only work in the browser
if (typeof document === 'undefined') return;

// allow you to work with cookies as objects.
if (typeof val === 'object') val = JSON.stringify(val);

document.cookie = cookie.serialize(name, val, opt);
}

Expand All @@ -34,4 +37,4 @@ if (typeof module !== 'undefined') {

if (typeof window !== 'undefined') {
window['reactCookie'] = reactCookie;
}
}

0 comments on commit 45a62ad

Please sign in to comment.