我正在使用redux-offline来处理应用程序内部的离线交互。重新启动应用时,我的 redux 存储中的脱机状态未保留。
例如,我的应用程序处于脱机状态,用户以调用要调度的操作的方式与应用交互。Redux-脱机将操作转移到处于 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-offline 应该可以修复它