0
我似乎無法設置redux-localstorage
模塊react-native
。我得到一個錯誤消息說:難以設置的REDX本地存儲與現有的商店
TypeError: (0, _reduxLocalstorage.mergePersistedState) is not a function. (In '(0, _reduxLocalstorage.mergePersistedState)()', '(0, _reduxLocalstorage.mergePersistedState)' is undefined)
這裏是我的configStore.jsx
文件的樣子。這是我最初使用thunk
中間件安裝我的redux商店的地方。網上沒有很多示例顯示如何設置redux-localstorage軟件包!我不是100%確定它是如何工作的。我只需要在localstorage內部存儲對象,這是用戶對象。其中將持有api authentication key + user details
。如果任何人都能指出我的方向,那將是驚人的!
const local_storage_reducer = compose(
mergePersistedState()
)(reducers);
const storage = compose(
filter('user'),
adapter(window.localStorage)
)
const createPersistentStore = compose(
applyMiddleware(thunk),
persistState(storage),
)(createStore);
const createStoreWithMiddleware = compose(
applyMiddleware(thunk),
persistState(storage, 'my-storage-key')
)(createStore);
export default function configureStore() {
return createStoreWithMiddleware(combineReducers(reducers));
}
export default function configurePersistentStore() {
return createPersistentStore(reducers);
}
以下是我如何通過provider
組件將商店注入到我的組件中。
const store = configureStore();
const persistentStore = configurePersistentStore();
<Provider store={[store,persistentStore] }>
.... Router stuff here ....
我不知道這是怎麼遠程設置你的redux-localstorage
還是我在正確的軌道上,並取得了一個小錯誤。
window.localStorage不存在陣營本土。看[AsyncStorage](https://facebook.github.io/react-native/docs/asyncstorage.html)。 –