【发布时间】:2017-08-10 20:25:03
【问题描述】:
我一直在尝试将 redux-persist 集成到一个已经使用 redux 的项目中。
我按照基本用法示例,但收到错误store.getState is not a function.
这是相关代码。
商店:
import {createStore, combineReducers, applyMiddleware, compose} from "redux";
import {persistStore, autoRehydrate} from 'redux-persist'
import thunk from "redux-thunk";
import marketData from "./reducers/marketDataReducer";
import coin from "./reducers/coinReducer";
import account from "./reducers/accountReducer";
const store = createStore(
combineReducers({
marketData,
coin,
account
}),
compose(
applyMiddleware(thunk),
autoRehydrate()
),
);
persistStore(store)
条目:
import { Navigation } from 'react-native-navigation';
import { registerScreens } from './navigation';
import Welcome from "./containers/welcome";
import store from "./store";
import { Provider } from 'react-redux';
registerScreens(store, Provider);
Navigation.startSingleScreenApp({
screen: {
screen: "welcome",
navigatorStyle: { navBarHidden: true }
}
});
编辑:解决方案非常简单。只要确保你导出你的商店。感谢@markerikson
【问题讨论】:
-
你真的是从
store.js导出store对象吗? -
我不认为,store 是在 Store js 文件中导出的。导出后,您应该让它运行 store.getState
-
哇哦。不错的地方。谢谢
-
@markerikson 您应该在答案中写下解决方案以获得更多可见性
标签: reactjs react-native redux react-redux persist