Skip to content

hardeepamritsar/react-native-saga-offline

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

react-native-saga-offline

Adds saga actions to offline queue if network is not reachable, dispatch offline actions once network becomes reachable

Installation

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

Link react-native-internet-reachability

react-native link react-native-internet-reachability

How it works

How to use

import createSagaOfflineMiddleware, { Connectivity } from 'react-native-saga-offline';


const sagaOffline = createSagaOfflineMiddleware();
this.store = this.createStore(
      persistedRootReducer,
      applyMiddleware(sagaOffline) // make sure sagaOffline is first middleware to be added
    );
    
new Connectivity(this.store);

Add reducer

import { offlineReducer } from 'react-native-saga-offline';


const appReducer = combineReducers({
  offline: offlineReducer,
});

Action with meta.retry : true would be queued as offline action

export const sagaAction = () => ({
  type: sagaActionsTypes.actionType,
  meta: {
    retry: true,
  },
});

Action from offline queue with have meta.actionFromOfflineQueue as true

About

Adds saga actions to offline queue if network is not reachable, dispatch offline actions once network becomes reachable

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published