【问题标题】:Redux Issue - store.getState is not a function. (In 'store.getState()', 'store.getState' is undefined)Redux 问题 - store.getState 不是函数。 (在 'store.getState()' 中,'store.getState' 未定义)
【发布时间】: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


【解决方案1】:

看起来您实际上并没有从store.js 文件中导出store 变量。先修复它,看看它是否有效。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-05-20
    • 2016-05-22
    • 2019-12-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-17
    相关资源
    最近更新 更多