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@bluedot-tech/react-uijacob-duong-awry-utilitiesimage-labeler-hdlgtmis-ant-componentslinkmore-designlin3s-sylius-shop-api-clientlinkhub-chat-pluginlinkhub-chat-plugin-commonlymyt-sdklymyt-sdk-testlzh_admin_vite@wearepsh/cra-template-react-ts@think-and-dev/cartesi-boardgame@tinper/next-share@unstoppabledomains/ui-components@ygyg/rc-channel@zalastax/nolb-react-cooadmin-templatesajuda-inicializacaoac-attachmentac-uploadac-upload-shanghaiawry-utilitiesawry-utilities-2awry-utilities-3@gvillette/boardgame.iosso-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@infinitebrahmanuniverse/nolb-react-coo@sagebrasil/sage.br.hypercube.web.components@seafile/sdoc-editor@seafile/seafile-metadatamongoose-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-upload
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