react-native-fetch-offline

1.1.1011 • Public • Published

react-native-fetch-offline

Returns fetch object with cached data if user is offline

Installation

npm install --save react-native-fetch-offline # with npm
yarn add react-native-fetch-offline # with yarn

Link react-native-internet-reachability

react-native link react-native-internet-reachability

How it works

How to use

import FetchOffline, { cacheReponse } from 'react-native-fetch-offline';
 
  const requestOptions = {
    method: 'GET',
    offline: {
      defaultResponse: {
        data: {
          myKey: 'myValue',
        }
      },
    },
  };
 
 
FetchOffline('http://www.domain.com/api', requestOptions)
    .catch(err => get(err, 'message', 'Default error message'))
    .then(response => response.json()
      .then((body) => {
        cacheReponse(requestOptions.url, fetchOptions, body); // if you want to cache response (to be returened for future calls while being offline)
        return body;
      }));

Package Sidebar

Install

npm i react-native-fetch-offline

Weekly Downloads

5

Version

1.1.1011

License

ISC

Unpacked Size

7.4 kB

Total Files

6

Last publish

Collaborators

  • hardeepsingh