robwalkerco / redux-persist-filesystem-storage

Redux persist adaptor for React Native filesystem storage
MIT License
196 stars 71 forks source link

Documentation says to pass FilesystemStorage to persistStore instead of persistReducer #29

Closed jsaraiva closed 6 years ago

jsaraiva commented 6 years ago

Using latest version of redux-persist ("^5.10.0") and redux-persist-filesystem-storage ("^1.3.1").

The documentation says to pass the FilesystemStorage to persistStore, like so:

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

I was only able to get this module to function if, instead of passing it to persistStore, I passed it to the topmost persistReducer call:

const persistConfig = {
  key: 'root',
  storage: FilesystemStorage
}
const persistedReducer = persistReducer(persistConfig, rootReducer)

Also related to this, the documentation says, in the "usage with custom options" section, that you can call .config on the FSS object, and pass the result to storage:

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

Actually, the config method doesn't return anything (https://github.com/robwalkerco/redux-persist-filesystem-storage/blob/master/index.js#L17), so you can just call it as soon as you load the module, and then pass the object later on to persistReducer:

FilesystemStorage.config({
     storagePath: `${RNFetchBlob.fs.dirs.DocumentDir}/persistStore`
});
const persistConfig = {
  key: 'root',
  storage: FilesystemStorage
}
const persistedReducer = persistReducer(persistConfig, rootReducer)
robwalkerco commented 6 years ago

Hi @jsaraiva,

Thanks for opening the issue.

I've just updated the README. Do you think anything else needs changing?

jsaraiva commented 6 years ago

Hi @robwalkerco ,

I think it looks great! This was the only issue that I had in getting the module to work, so I don't believe that the README requires any further changes.

Thanks!