[英]Offline state not rehydrating with redux-offline
我正在使用redux-offline來處理應用程序內部的脫機交互。 重新啟動應用程序后,我的redux存儲中的脫機狀態不會保持不變。
例如,我的應用程序處於脫機狀態,並且用戶以調用要分派的動作的方式與該應用程序進行交互。 Redux-offline將操作轉移到Redux存儲處於脫機狀態的發件箱陣列,當應用程序重新聯機時,該操作應重試該操作。 如果我這樣做並讓操作處於脫機狀態排隊,然后重新啟動應用程序(仍處於脫機狀態),則Redux存儲將保留除脫機狀態以外的所有內容,因此我將丟失排隊的項目。
我的商店配置代碼如下。 我已經編寫了某種方式,以便顯示初始屏幕,直到redux商店重新水化為止。
import React, { Component } from "react"
import { AsyncStorage } from "react-native"
import { Provider } from "react-redux"
import { applyMiddleware, compose, createStore } from "redux"
import thunk from "redux-thunk"
import { autoRehydrate, persistStore } from "redux-persist"
import logger from "redux-logger"
import { offline } from "redux-offline"
import offlineConfig from "redux-offline/lib/defaults"
import reducers from "./redux/modules"
import MyApp from "./MyApp"
import SplashScreen from "./components/home/SplashScreen"
const store = createStore(
reducers,
undefined,
compose(applyMiddleware(thunk, logger), offline(offlineConfig))
)
export default class Setup extends Component {
constructor(props) {
super(props)
this.state = {
rehydrated: false
}
}
componentWillMount() {
persistStore(store, { storage: AsyncStorage }, () => {
this.setState({ rehydrated: true })
})
}
render = () =>
!this.state.rehydrated ? (
<SplashScreen />
) : (
<Provider store={store}>
<MyApp />
</Provider>
)
}
使用Redux工具進行檢查-可能會使離線商店重新水化,但是一旦設置了狀態,它就會立即更改,更新到最新的Redux-offline應該可以修復它
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.