0.1.1 • Published 6 years ago

react-cookies v0.1.1

Weekly downloads
37,114
License
MIT
Repository
github
Last release
6 years ago

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

@pronto-development/pronto-componentsinfoniqa-client-core@danielballardp/infoniqa-client-corewkwkwk-jsboardgame.iojuzq-reactuitest-theme-shawacademy@toplion/components@luxrobo/entry-toolooxx_uidemo@toplion/webbos-document-ceshi@bos-document-ceshi/documentkfcomponentfrontend_ky@wbts/commonfamom-ui3@everything-registry/sub-chunk-2547@ihezebin/doraemonzhframeweb-eventvolantis-marketplacevalpio-react-shop-middleware@djmax/boardgame.io@databraid/github-widget@databraiddev/github-widget@bluedot-tech/react-uijacob-duong-awry-utilitiessso-clienttoukaticketmelon-webtoplionwebttv@abimato/axios@abimato/helpers@abimato/utilities@bos-alpha/common@bos-alpha/data@bos-alpha/document@bos-alpha/geo-scene@bos-alpha/iot@bos-alpha/progress@bos-alpha/ucenter@bos-model-alpha/data@bos-model-alpha/ucenterzb-fitment-corezb-fitment-uizb-componentszbdx-fitment-coreyg-portaljs-sdkyunmuzhframe-testzhframe-vite-v3zq-react-uizq-react-ui-2wanpng-uikit@dumpster-fire/boardgame.io@gvillette/boardgame.io@ihezebin/common@freeboardgame.org/boardgame.io@gdatabraid/github-widget2@evandroabukamel/boardgame.io@indecbimtest/commonlibrary@infinitebrahmanuniverse/nolb-react-coo@nomoid/boardgame.io-ui@entrylabs/tool@joepinion/boardgame.io@omidanalyzer/event-controller@monx/default-providers@sagebrasil/sage.br.hypercube.web.components@ooxx87/famsun-ui@smileyjames/boardgame.io@seafile/sdoc-editor@seafile/seafile-metadata@shiyanan/documentmongoose-admin-panel-frontendmicrosite-uip24-react-baseopal_flibnotrestudiooflibpeacetrue-boardgame.iosc-sierrasecondstep-marketingreact-adminlte-componentsreact-basic-componentreact-curiobites-coursesea-ai-ui-componentreactratingroutingseatable-ai-ui-componentpossum-ui-commercepossum-utilitiespndashqmac-uploadqhc_job_uips-pack-componentpublisher-consolereact-rjillsimple-react-form-builderreact-video-trimmer
0.1.2-beta.0

6 years ago

0.1.1

6 years ago

0.1.0

8 years ago

0.0.1

8 years ago