0.0.6 • Published 3 years ago

@vahesaroyan/redux-offline v0.0.6

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago
yarn add @vahesaroyan/redux-offline
Fixed work for react native support

example:
import { createStore, applyMiddleware } from 'redux'
import AsyncStorage from '@react-native-community/async-storage'
import { composeWithDevTools } from 'redux-devtools-extension'
import { persistStore, persistReducer } from 'redux-persist'
import thunk from 'redux-thunk'
import reducer from '@/reducers'

import { createOffline } from '@vahesaroyan/redux-offline'
import offlineConfig from '@vahesaroyan/redux-offline/lib/defaults/index'

const persistConfig = {
  key: 'root',
  storage: AsyncStorage,
}

const {
  middleware: offlineMiddleware,
  enhanceReducer: offlineEnhanceReducer,
  enhanceStore: offlineEnhanceStore,
} = createOffline({
  ...offlineConfig,
  persist: false,
})

const persistedReducer = persistReducer(
  persistConfig,
  offlineEnhanceReducer(reducer),
)

const store = createStore(
  persistedReducer,
  composeWithDevTools(
    offlineEnhanceStore,
    applyMiddleware(thunk, offlineMiddleware),
  ),
)
const persistor = persistStore(store)

export { store, persistor }