0.1.1 • Published 5 years ago

react-cookies v0.1.1

Weekly downloads
37,114
License
MIT
Repository
github
Last release
5 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/doraemonzhframeoflibp24-react-basenotrestudiopeacetrue-boardgame.iopndashopal_flibpossum-ui-commercepossum-utilitiespublisher-consoleqhc_job_ui@djmax/boardgame.io@databraid/github-widget@databraiddev/github-widgetcerebro-npm-test@freeboardgame.org/boardgame.ioweb-eventzq-react-uizq-react-ui-2zhframe-testzhframe-vite-v3zb-componentszb-fitment-corezb-fitment-uizbdx-fitment-core@gdatabraid/github-widget2wanpng-uikityg-portaljs-sdkyunmuvolantis-marketplacecloud-toplioncodesfish-admin-layoutreact-video-trimmerreact-rjillreact-basic-componentreact-adminlte-componentsreact-curiobites-courseps-pack-componentreactjs-chatappreactratingroutingqmac-uploadsc-sierraticketmelon-webtoukasea-ai-ui-componentsecondstep-marketingsimple-react-form-builderseatable-ai-ui-componentsso-clientttvvalpio-react-shop-middlewarefamom-uifamom-ui2family_onefamsun-mobile-uifamsun-uicowx-platform-computer-web@infinitebrahmanuniverse/nolb-react-coo@monx/default-providers@omidanalyzer/event-controller@ooxx87/famsun-uigtmis-ant-componentsformmanagerlibform_manager_opalflamecoals-boardgame.io@joepinion/boardgame.io@indecbimtest/commonlibraryimage-labeler-hdl@sagebrasil/sage.br.hypercube.web.components@dumpster-fire/boardgame.io@gvillette/boardgame.io@hezebin/doraemondapparatus@ihezebin/commoncuriobites-chatentry-tool@smileyjames/boardgame.io@seafile/sdoc-editor@evandroabukamel/boardgame.io@shiyanan/documentjacob-duong-awry-utilities
0.1.2-beta.0

5 years ago

0.1.1

5 years ago

0.1.0

7 years ago

0.0.1

7 years ago