diff --git a/index.js b/index.js index df7745f..cbd51ac 100644 --- a/index.js +++ b/index.js @@ -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); } @@ -34,4 +37,4 @@ if (typeof module !== 'undefined') { if (typeof window !== 'undefined') { window['reactCookie'] = reactCookie; -} \ No newline at end of file +}