$ npm install react-cookies
Load and save cookies with React
$ yarn add react-cookies
// 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>
}
}
Set a cookie.
The cookie name
Type: string
Required
The cookie value
Type: any
Required
Support all the cookie options from the RFC 6265.
Type: object
Get a cookie.
The cookie name.
Type: string
Required
Remove a cookie.
The cookie name.
Type: string
Required
Get all cookies.
MIT © Bu Kinoshita
© 2010 - cnpmjs.org x YWFE | Home | YWFE