redux-offline-queue-too
Forked from redux-offline-queue
made by InspireNL.
This package is a simple solution for handling actions or requests with redux while the app is in an offline state by queueing these, and dispatching them once connectivity is re-established. Works perfect with react-native
Motivation: Provide a better user experience.
Installation
npm install --save redux-offline-queue-too
redux-offline-queue
Usage - NOTE: This won't apply to this repo, but for See example project here: offlineTweet
Get up and running in 4 easy steps:
Step 1: Add the redux-offline-queue reducer to your combine reducers
Either import the { reducer as offlineQueue }
from redux-offline-queue
and add it to the combineReducers
or require it like so (whatever floats your boat):
; offlineQueue: reducer yourOtherReducer: reducer;
Step 2: Add the offlineMiddleware
; const composeStoreWithMiddleware = createStore;
Note that this queue is not persisted by itself. One should provide a persistence config by using e.g. redux-persist
to keep the offline queue persisted.
Step 3: Declare the actions to be queued
reduxsauce
With const Types Creators = ...
Without
const Creators = type: 'CREATE_BLOG' blog ...
Last but not least...
Step 4: Monitor the connectivity and let the library know.
; if appIsConnected ; else ;
Works perfect with React Native's NetInfo
;;; { const channel = ; try for ;; const isConnected = ; if isConnected ; else ; finally channel; }
Android
If react native's NetInfo
is intended to be used, for android don't forget to add the following to the AndroidManifest.xml
:
Inspired by redux-queue-offline(mathieudutour)
Developed by Krzysztof Ciombor
Compatibility
redux-saga
with If you are using redux-sagas
for http requests and want to fire your redux actions normally, but suspend(queue) sagas, for Step 2, do the following instead:
;;; const middleware = ; middleware;const suspendSagaMiddleware = ;middleware;middleware; ;
It is IMPORTANT that the consumeActionMiddleware
is placed last, so you can allow the previous middlewares to react first before eventually getting consumed.
Additional Configuration
Additional configuration can be passed with offlineMiddleware()
, such as adding additional triggers that will trigger the offline queue to dispatch its actions:
... ...