- Notifications
You must be signed in to change notification settings - Fork72
Redux persist adaptor for React Native filesystem storage
License
robwalkerco/redux-persist-filesystem-storage
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Storage adaptor to usereact-native-blob-util withredux-persist, by implementing the needed methods:setItem,getItem,removeItem,getAllKeys andclear.
This storage can be used on Android to prevent issues with the storage limitations in the RN AsyncStorage implementation. (Seeredux-persist#199,redux-persist#284)
Please note: v2 of this library supports React Native 0.60 and above only. If you are using React Native 0.59 and below, please use v1.x.
yarn add redux-persist-filesystem-storage
or, for React Native 0.59 and below:
yarn add redux-persist-filesystem-storage@1
Then, asreact-native-blob-util is a dependency of this project, it will also need setting up as itstheir installation docs.
Simply use 'FilesystemStorage' as the storage option in the redux-persist config.
importFilesystemStoragefrom'redux-persist-filesystem-storage'...constpersistConfig={key:'root',storage:FilesystemStorage,}...
importFilesystemStoragefrom'redux-persist-filesystem-storage'...// These are all the config options, with their default valuesFilesystemStorage.config({storagePath:`${RNFetchBlob.fs.dirs.DocumentDir}/persistStore`,encoding:"utf8",toFileName:(name:string)=>name.split(":").join("-"),fromFileName:(name:string)=>name.split("-").join(":"),});constpersistConfig={key:'root',storage:FilesystemStorage,toFileName:(name:string)=>name.split(":").join("-"),fromFileName:(name:string)=>name.split("-").join(":")}...
Using redux-persist V5?
Redux-Persist v5 migrate from one storage system to another
Using redux-persist V4?
the snippet below lets you migrate redux data previously stored inAsyncStorage toredux-persist-filesystem-storage.
NOTE This snippet lets you migratehealthy data. Itwill not restoredata if it is already hit limits ofAsyncStorage
import{persistStore,getStoredState}from'redux-persist'importFilesystemStoragefrom'redux-persist-filesystem-storage'import{AsyncStorage}from'react-native'import_from'lodash'import{createStore}from'redux'conststore=createStore(...)// create persistor for `redux-persist-filesystem-storage`constfsPersistor=persistStore(store,{storage:FilesystemStorage},async(fsError,fsResult)=>{if(_.isEmpty(fsResult)){// if state from fs storage is empty try to read state from previous storagetry{constasyncState=awaitgetStoredState({storage:AsyncStorage})if(!_.isEmpty(asyncState)){// if data exists in `AsyncStorage` - rehydrate fs persistor with itfsPersistor.rehydrate(asyncState,{serial:false})}}catch(getStateError){console.warn("getStoredState error",getStateError)}}})
About
Redux persist adaptor for React Native filesystem storage
Resources
License
Code of conduct
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors15
Uh oh!
There was an error while loading.Please reload this page.