Froelund / redux-persist-filesystem-storage

Redux persist adaptor for React Native filesystem storage

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Redux persist filesystem storage

npm version npm downloads

Storage adaptor to use react-native-fetch-blob with redux-persist, by implementing the needed methods: setItem, getItem, removeItem and getAllKeys

This storage can be used on Android to prevent issues with the storage limitations in the RN AsyncStorage implementation. (See redux-persist#199, redux-persist#284)

install

yarn add redux-persist-filesystem-storage

Then, as react-native-fetch-blob is a dependency of this project, we need to ensure its linked with

react-native link react-native-fetch-blob

(or check their docs).

usage

import FilesystemStorage from 'redux-persist-filesystem-storage'
import { persistStore, autoRehydrate } from 'redux-persist'

const store = createStore(reducer, undefined, autoRehydrate())

persistStore(
  store,
  {
    storage: FilesystemStorage,
  },
)

usage with custom options

import RNFetchBlob from 'react-native-fetch-blob'
import FilesystemStorage from 'redux-persist-filesystem-storage'
import { persistStore, autoRehydrate } from 'redux-persist'

const store = createStore(reducer, undefined, autoRehydrate())

persistStore(
  store,
  {
    storage: FilesystemStorage.config(
      {
        storagePath: `${RNFetchBlob.fs.dirs.DocumentDir}/persistStore`,
      },
    },
  )
)

About

Redux persist adaptor for React Native filesystem storage


Languages

Language:JavaScript 100.0%