react-cookie
Advanced tools
Comparing version 0.1.7 to 0.1.8
18
index.js
@@ -19,12 +19,22 @@ var cookie = require('cookie'); | ||
_cookies[name] = val; | ||
// Cookies only work in the browser | ||
if (typeof document === 'undefined') return; | ||
// allow you to work with cookies as objects. | ||
// make sure a serialized value returns as serialized again | ||
if (typeof val === 'object' || typeof val === 'string') val = JSON.stringify(val); | ||
document.cookie = cookie.serialize(name, val, opt); | ||
} | ||
function remove(name) { | ||
if (typeof document === 'undefined') return; | ||
document.cookie = name + '=; expires=Thu, 01 Jan 1970 00:00:01 GMT;'; | ||
} | ||
var reactCookie = { | ||
load: load, | ||
save: save | ||
save: save, | ||
remove: remove | ||
}; | ||
@@ -38,2 +48,2 @@ | ||
window['reactCookie'] = reactCookie; | ||
} | ||
} |
{ | ||
"name": "react-cookie", | ||
"version": "0.1.7", | ||
"version": "0.1.8", | ||
"description": "Load and save cookies within your React application", | ||
@@ -5,0 +5,0 @@ "main": "dist/react-cookie.min.js", |
# react-cookie | ||
Load and save cookies within your React application | ||
Load, save and remove cookies within your React application | ||
If you are within a non-browser environment, it will do nothing and not crash. | ||
## Download | ||
NPM: `npm install react-cookie`<br /> | ||
Bower: `bower install react-cookie` | ||
Bower: `bower install react-cookie`<br /> | ||
CDN: `https://cdnjs.cloudflare.com/ajax/libs/react-cookie/0.1.8/react-cookie.min.js` | ||
@@ -27,2 +30,6 @@ # Examples | ||
onLogout() { | ||
cookie.remove('userId'); | ||
} | ||
render() { | ||
@@ -53,2 +60,6 @@ return ( | ||
onLogout: function() { | ||
cookie.remove('userId'); | ||
}, | ||
render: function() { | ||
@@ -74,2 +85,3 @@ return ( | ||
### `reactCookie.save(name, val, [opt])` | ||
### `reactCookie.remove(name)` | ||
@@ -98,2 +110,2 @@ ## opt | ||
## License | ||
This project is under the MIT license. You are free to do whatever you want with it. | ||
This project is under the MIT license. You are free to do whatever you want with it. |
Sorry, the diff of this file is not supported yet
4943
36
108