Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Redux persist adaptor for React Native filesystem storage

License

NotificationsYou must be signed in to change notification settings

robwalkerco/redux-persist-filesystem-storage

Repository files navigation

npm versionnpm downloads

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)

install

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.

usage

Simply use 'FilesystemStorage' as the storage option in the redux-persist config.

importFilesystemStoragefrom'redux-persist-filesystem-storage'...constpersistConfig={key:'root',storage:FilesystemStorage,}...

usage with custom options

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(":")}...

migration from previous storage

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

Stars

Watchers

Forks

Packages

No packages published

Contributors15


[8]ページ先頭

©2009-2025 Movatter.jp