Giter Club home page Giter Club logo

react-cookies's Introduction

react-cookies

Load and save cookies with React

Install

$ yarn add react-cookies

API

.setCookie(name, value, [options])

Set a cookie.

name

The cookie name

Type: string
Required

value

The cookie value

Type: any
Required

options

Support all the cookie options from the RFC 6265.

Type: object

  • expire: Indicates the maximum lifetime of the cookie represented as the date and time
  • maxAge: Indicates the maximum lifetime of the cookie represented as the number of seconds
  • domain: Specifies those hosts to which the cookie will be sent
  • path: The scope of each cookie is limited to a set of paths
  • secure: Limits the scope of the cookie to "secure" channels (where "secure" is defined by the user agent)
  • httpOnly: Limits the scope of the cookie to HTTP requests

.getCookie(name)

Get a cookie.

name

The cookie name.

Type: string
Required

.removeCookie(name)

Remove a cookie.

name

The cookie name.

Type: string
Required

.getAllCookies()

Get all cookies.

License

MIT ยฉ Bu Kinoshita

react-cookies's People

Contributors

bukinoshita avatar dependabot[bot] avatar evenstensberg avatar renovate[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

react-cookies's Issues

expires is not working!

Hello,
I am trying to set cookie with expires option but it is not working.

let currentDate = new Date();
let expireDate = new Date(currentDate.getFullYear(), currentDate.getMonth(),currentDate.getDate()+1), 0,0,0);
console.log(expireDate);
console.log(typeof(expireDate));
return cookie.save(key, value, { path: "/", expires: expireDate});

console shows right date and type is object.
but it is not setting any cookie. Without expires it is working fine.
This is the behaviour in chrome, in firefox it is working fine.

Cookie persist

Hi,

I'm using chrome with react. And after saveCookie, when i close the browser and restart the browser my cookie is not persist.

var base64 = btoa(newSplittersPositionString); // save the data to base64 cookie.save(Constants.COOKIE_SPLITTER, base64);

Can you help me?

thanks

maxAge not working on IE11

I've set MaxAge to 20 years in order to save the cookies in persistent.
it's working fine on both Chrome and firefox, but not working on IE11.
Cookies get deleted when browser closes.

cookies.set('checkedItems', JSON.stringify(checkedItemsArr), {path: '/', maxAge: 630720000 })

Is this not IE compatible?

add typescript declaration

I'm wandering now more and more react developers want to use Typescript to program. So after some days I want to make a PR to add the .d.ts into the package.

Sample code needs to be updated

The component works great, but the sample code needs to be updated. Domain needs to be changed to host and the code you are using to set the expires date does not return a valid date. I fixed both as follows โ€” if you update the example you wont have to change the code at all. Best of luck and thank you :)

 const expires = new Date();
    expires.setDate(14); //14 days in the future
    cookie.save("cookie-name", "value", {
      path: "/",
      expires,
      host: "https://*.hostname"
    }); 

readme needs to be updated

the readme file needs to be updated as it doesn't depict exactly what you need to do to use the react-cookies

No Declaration File

When I import react-cookies into my project.

Like this

import cookies from 'react-cookies';

I get an error that reads:

Could not find a declaration file for module 'react-cookies'. '.../node_modules/react-cookies/build/cookie.js' implicitly has an 'any' type.
Try npm install @types/react-cookies if it exists or add a new declaration (.d.ts) file containing declare module 'react-cookies';ts(7016)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.