react-cookies
Load and save cookies with React
Last updated 7 years ago by bukinoshita .
MIT · Repository · Original npm · Tarball · package.json
$ npm install react-cookies 
SYNC missed versions from official npm registry.

react-cookies Build Status

Load and save cookies with React

Install

$ yarn add react-cookies

Quick start

// Packages
import React from 'react'
import { setCookie, getCookie, removeCookie } from 'react-cookies'

class Example extends Component {
  componentDidMount() {
    setCookie('my-cookie', 'my-cookie-value', {
      maxAge: 30 * 24 * 60 * 60,
      path: '/'
    })

    getCookie('my-cookie')

    removeCookie('my-cookie')
  }

  render() {
    return <h1>My example</h1>
  }
}

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

Current Tags

  • 0.1.2-beta.0                                ...           beta (7 years ago)
  • 0.1.1                                ...           latest (8 years ago)

4 Versions

  • 0.1.2-beta.0                                ...           7 years ago
  • 0.1.1                                ...           8 years ago
  • 0.1.0                                ...           9 years ago
  • 0.0.1                                ...           10 years ago
Maintainers (1)
Downloads
Total 9
Today 0
This Week 0
This Month 3
Last Day 0
Last Week 2
Last Month 3
Dependencies (1)
Dev Dependencies (6)
Dependents (0)
None

© 2010 - cnpmjs.org x YWFE | Home | YWFE