Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-cookie

Package Overview
Dependencies
Maintainers
1
Versions
84
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-cookie - npm Package Compare versions

Comparing version 2.1.7 to 2.2.0

64

lib/withCookies.js

@@ -9,2 +9,4 @@ 'use strict';

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
exports.default = withCookies;

@@ -30,22 +32,55 @@

function withCookies(Component) {
function Wrapper(props, _ref) {
var cookies = _ref.cookies;
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var wrappedComponentRef = props.wrappedComponentRef,
remainingProps = _objectWithoutProperties(props, ['wrappedComponentRef']);
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
return _react2.default.createElement(Component, _extends({}, remainingProps, {
cookies: cookies,
ref: wrappedComponentRef
}));
}
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
Wrapper.displayName = 'withCookies(' + (Component.displayName || Component.name) + ')';
Wrapper.WrappedComponent = Component;
function withCookies(WrapperComponent) {
var Wrapper = function (_Component) {
_inherits(Wrapper, _Component);
function Wrapper(props, context) {
_classCallCheck(this, Wrapper);
var _this = _possibleConstructorReturn(this, (Wrapper.__proto__ || Object.getPrototypeOf(Wrapper)).call(this, props));
_this.onChange = function () {
_this.forceUpdate();
};
context.cookies.addChangeListener(_this.onChange);
return _this;
}
_createClass(Wrapper, [{
key: 'componentWillUnmount',
value: function componentWillUnmount() {
this.context.cookies.removeChangeListener(this.onChange);
}
}, {
key: 'render',
value: function render() {
var _props = this.props,
wrappedComponentRef = _props.wrappedComponentRef,
remainingProps = _objectWithoutProperties(_props, ['wrappedComponentRef']);
var allCookies = this.context.cookies.getAll();
return _react2.default.createElement(WrapperComponent, _extends({}, remainingProps, {
cookies: this.context.cookies,
allCookies: allCookies,
ref: wrappedComponentRef
}));
}
}]);
return Wrapper;
}(_react.Component);
Wrapper.displayName = 'withCookies(' + (_react.Component.displayName || _react.Component.name) + ')';
Wrapper.WrapperComponent = WrapperComponent;
Wrapper.propTypes = {
wrappedComponentRef: _propTypes.func
};
Wrapper.contextTypes = {

@@ -55,4 +90,5 @@ cookies: (0, _propTypes.instanceOf)(_universalCookie2.default).isRequired

return (0, _hoistNonReactStatics2.default)(Wrapper, Component);
return (0, _hoistNonReactStatics2.default)(Wrapper, WrapperComponent, { WrappedComponent: true });
}
module.exports = exports['default'];
{
"name": "react-cookie",
"version": "2.1.7",
"version": "2.2.0",
"description": "Universal cookies for React",

@@ -31,3 +31,3 @@ "main": "lib/index.js",

"prop-types": "^15.0.0",
"universal-cookie": "^2.1.5"
"universal-cookie": "^2.2.0"
},

@@ -34,0 +34,0 @@ "devDependencies": {

@@ -28,3 +28,5 @@ <h3 align="center">

## `withCookies(Component)`
Give access to cookies by providing it using the `cookies` prop.
Give access to your cookies anywhere. Add the following props to your component:
- cookies: Cookies instance allowing you to get, set and remove cookies.
- allCookies: All your current cookies in an object.

@@ -96,5 +98,6 @@ ## Cookies

componentWillMount() {
const { cookies } = this.props;
constructor(props) {
super(props);
const { cookies } = props;
this.state = {

@@ -141,5 +144,6 @@ name: cookies.get('name') || 'Ben'

componentWillMount() {
const { cookies } = this.props;
constructor(props) {
super(props);
const { cookies } = props;
this.state = {

@@ -146,0 +150,0 @@ name: cookies.get('name') || 'Ben'

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc