0.1.1 • Published 5 years ago
react-cookies v0.1.1
react-cookies
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