我正在使用 react-native-navigation 和 redux 进行状态管理。我将每个组件注册为 WrappedComponent,将其连接到 redux 存储。这非常有效,并且与官方 react-native-navigation 文档中的 atoami 示例代码非常相似:https ://wix.github.io/react-native-navigation/#/docs/showcases
import { Provider } from "react-redux";
import store from "./config/store";
...
function WrappedComponent(Component) {
return function inject(props) {
const EnhancedComponent = () => (
<Provider store={store}>
<Component {...props} />
</Provider>
);
return <EnhancedComponent />;
};
}
export function registerScreens() {
Navigation.registerComponent("Initializing", () =>
WrappedComponent(InitializingScreen)
);
Navigation.registerComponent("SignIn", () => WrappedComponent(SignInScreen));
...
}
商店对象为:
import { createStore, compose, applyMiddleware } from "redux";
import thunk from "redux-thunk";
import reducers from "../reducers";
const composeEnhancer = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
export default createStore(
reducers,
composeEnhancer(applyMiddleware(thunk))
);
但是,我找不到为那些包装的组件设置 redux 持久性的方法。我不想在WrappedComponent
函数中执行它,因为它会被每个单独的组件调用。我也找不到关于此的明确文档。
我想我也可以使用 AsyncStorage,但更愿意将它与 Redux-persist 一起使用。有人知道该怎么做吗?