as

Settings
Sign out
Notifications
Alexa
Amazon Appstore
Ring
AWS
Documentation
Support
Contact Us
My Cases
Get Started
Design and Develop
Publish
Reference
Support

react-native-cookies

The @amazon-devices/react-native-cookies library provides a way for React Native applications to manage cookies.

A cookie is a small piece of data stored on the user's device by the web browser while browsing a website. Cookies are designed to be a reliable mechanism for websites to remember stateful information or to record the user's browsing activity.

Installation

  1. Add the JavaScript library dependency in the package.json file:

    Copied to clipboard.

           "dependencies": {
             ...
             "@amazon-devices/react-native-cookies__cookies": "1.0.1+6.2.1",
             "@react-native-cookies/cookies": "6.2.1",
             ...
           }
    
  2. Reinstall dependencies using the npm install command.

Example

The following example shows all methods already implemented in this library.

Copied to clipboard.

import CookieManager, { Cookie } from "@react-native-cookies/cookies";
import React, { useState } from 'react';
import { Button, ScrollView, StyleSheet, Text, View } from 'react-native';

const App = () => {
  const [response, setResponse] = useState('');

  const mockedCookie: Cookie = {
    name: 'myCookie',
    value: 'myValue',
    domain: 'httpbin.org',
    path: '/',
    httpOnly: true,
    expires: '2030-06-01T12:30:00.00-05:00'
  };

  const url = "https://httpbin.org";

  const testMockedFunction = async (func: (...args: any[]) => Promise<any>, ...args: any) => {
    try {
      setResponse("");
      await func(...args).then(
        (result : any) => setResponse(JSON.stringify(result)),
        (reject : any) => setResponse(JSON.stringify(reject))
      );

    } catch(err) {
      if (err instanceof Error) {
        setResponse(err.message);
      }
    }
  };

  const fetchTest = async () => {
    setResponse("");
    const result = await fetch("https://httpbin.org/get");
    setResponse(`${await result.text()}`);
  };

  return (
    <View style={styles.container}>
      <View style={styles.textArea}>
        <ScrollView>
            <Text style={styles.text} numberOfLines={999}>
                {response}
            </Text>
        </ScrollView>
      </View>
      <View style={[styles.buttonRow, { width: 800 }]}>
          <Button title ={"Fetch from httpbin.org"} onPress={() => fetchTest()} />
          <Button title={"Test set method"} onPress={() => testMockedFunction(CookieManager.set, url, mockedCookie)} />
          <Button title={"Get httpbin.org Cookies"} onPress={() => testMockedFunction(CookieManager.get, url)} />
          <Button title={"Clear All Cookies"} onPress={() => testMockedFunction(CookieManager.clearAll)} />
      </View>
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    backgroundColor: '#dfebeb',
    justifyContent: 'center',
    paddingHorizontal: 5,
    flex: 1,
    display: 'flex',
    alignItems: 'center',
    overflow: 'hidden',
  },
  textArea: {
    width: 750,
    height: 250,
    alignItems: 'center',
    marginVertical: 20
  },
  buttonRow: {
    flexDirection: 'row',
    marginVertical: 10,
    justifyContent: 'space-between'
  },
  text: {
    color: 'black',
    fontFamily: 'monospace',
    overflow: 'scroll',
    flex: 1,
  }
});

export default App;

API reference

Check out the official README from @react-native-cookies/cookies's GitHub repository.

The list below shows the current state of implemented functionalities.

Method Description
set Set a cookie given a Cookie object and a URL
get Get cookies for a URL
clearAll Clear cookies
  • When no domain field is specified for the Cookie object, a URL host is used instead.
  • When no path is specified for the Cookie object, an empty path / is assumed.
  • Setting useWebKit = true on the Vega platform, for methods that accept the parameter, is a no-op. If no value is provided, useWebKit defaults to false.
  • Passing a malformed URL, to any methods that accept a URL, returns an error message.

Implementation details

  • The accepted date-time format for the expires field of a Cookie object is the ISO8601 format with an offset from UTC. After a cookie is set on Vega, the date-time is always converted to GMT.
    • For example, after mockedCookie from the previous example is set, subsequent retrievals return a timestamp of expires: '2030-06-01T17:30:00.00Z'. This timestamp is the equivalent time in GMT.
  • When session cookies (cookies with no expires field) are retrieved with get, the expires field is populated with 1970-01-01T00:00:00Z. If this cookie is used with other Cookie Managers, remove the field from the cookie. Otherwise, the cookie is read as expired by other Cookie Manager implementations (such as Webview Cookie Manager).

Supported versions

Package name Amazon NPM library version Vega OS build number Vega SDK version Release notes
@amazon-devices/react-native-cookies__cookies 1.0.1+6.2.1 OS 1.1 (201010438050) 0.20  

Additional resources

For information on other libraries, see Supported Third-Party Libraries and Services.


Last updated: Oct 02, 2025