react-native-cookie
A cookie manager module for react-native(Supports for both iOS and Android).Installation
# install library from npm
npm install react-native-cookie --save
# link native code
react-native link react-native-cookie
Usage
Import
import Cookie from 'react-native-cookie';
Get
Cookie.get(url:String, name?: String): Promise<Object|String>
// get all cookies which are belonged to 'http://bing.com/'
Cookie.get('http://bing.com/').then((cookie) => console.log(cookie));
// get cookie named 'foo' from 'http://bing.com/'
Cookie.get('http://bing.com/', 'foo').then((cookie) => console.log(cookie));
Set
Cookie.set(url:String, name: String, value: any, options?: Object): Promise
Options
The following options are available for now- domain
- expires
- path
// set cookie 'foo=bar' for 'http://bing.com/'
Cookie.set('http://bing.com/', 'foo', 'bar').then(() => console.log('success'));
// set cookie 'foo=bar' for 'http://bing.com/' with options:
Cookie.set('http://bing.com/', 'foo', 'bar', {
path: 'ditu',
domain: 'cn.bing.com'
}).then(() => console.log('success'));
Clear
Cookie.clear(url?: String): Promise
// clear all cookies for all domains
Cookie.clear();
// clear all cookies for 'http://bing.com'
Cookie.clear('http://bing.com');