react-cookie
Advanced tools
Comparing version 0.1.1 to 0.1.7
var cookie = require('cookie'); | ||
var _cookies = cookie.parse((document && document.cookie) ? document.cookie : ''); | ||
var _cookies = cookie.parse((typeof document !== 'undefined') ? document.cookie : ''); | ||
@@ -18,6 +18,7 @@ for (var key in _cookies) { | ||
function save(name, val, opt) { | ||
_cookies[name] = val; | ||
// Cookies only work in the browser | ||
if (!document || !document.cookie) return; | ||
_cookies[name] = val; | ||
if (typeof document === 'undefined') return; | ||
document.cookie = cookie.serialize(name, val, opt); | ||
@@ -24,0 +25,0 @@ } |
{ | ||
"name": "react-cookie", | ||
"version": "0.1.1", | ||
"version": "0.1.7", | ||
"description": "Load and save cookies within your React application", | ||
"main": "index.js", | ||
"main": "dist/react-cookie.min.js", | ||
"files": [ | ||
@@ -24,3 +24,3 @@ "index.js" | ||
"scripts": { | ||
"build": "browserify index.js > dist/react-cookie.js & uglifyjs dist/react-cookie.js -o dist/react-cookie.min.js" | ||
"build": "mkdir dist & browserify index.js > dist/react-cookie.js & uglifyjs dist/react-cookie.js -o dist/react-cookie.min.js" | ||
}, | ||
@@ -27,0 +27,0 @@ "dependencies": { |
@@ -15,3 +15,3 @@ # react-cookie | ||
export default class MyApp extends React.component { | ||
export default class MyApp extends React.Component { | ||
@@ -25,3 +25,3 @@ constructor(props) { | ||
this.state.userId = userId; | ||
cookie.save('userId', nextState.userId); | ||
cookie.save('userId', userId); | ||
} | ||
@@ -51,3 +51,3 @@ | ||
this.state.userId = userId; | ||
cookie.save('userId', nextState.userId); | ||
cookie.save('userId', userId); | ||
}, | ||
@@ -66,6 +66,11 @@ | ||
## Without CommonJS | ||
You can use react-cookie with anything by using the global variable `reactCookie`. | ||
*Note that `window` need to exists to use `reactCookie`.* | ||
## Usage | ||
### `reactCookie.load(name: string)` | ||
### `reactCookie.save(name: string, val, [opt])` | ||
### `reactCookie.load(name)` | ||
### `reactCookie.save(name, val, [opt])` | ||
@@ -72,0 +77,0 @@ ## opt |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4416
95