TypeError:未定义不是函数(正在评估'store.getState()')

时间:2019-05-31 06:37:05

标签: react-native react-redux

我已经使用redux进行了反应16.6.3,以便在组件内传递参数并将文件数据发送到后端。 我添加了reducers.js,actions.js,store.js并将它们添加到我的组件中,但是它会生成未定义的错误,而不是一个函数(评估'store.getState()')。因此请帮助我解决此错误。谢谢大家的先进。

我将react版本更改为并重新安装react-redux。 React store.getState is not a function我也尝试了这个建议。它行不通。

 reducers/index.js
    let initialStateMarker = {
        markers : []
    }

    const farmLocReducer=(state = initialStateMarker , action) => {
        switch (action.type) {
            case ADD_FARM_LOC:
                state = Object.assign({}, state, {
                    farmIndex: action.farmIndex
                });
                return state;
            default:
                return state;
        }
        ;
    }


     // this.index.farmLocReducer.farmLocReducer

    const rootReducer = combineReducers({
        farmLocReducer: farmLocReducer,
    })

    export default rootReducer;


    store/index.js
import {createStore, applyMiddleware} from 'redux';
    import {createContext} from "react";
    import thunk from 'redux-thunk';

    import rootReducer from '../reducers'; //Import the reducer

    const store = createContext(createStore(rootReducer, applyMiddleware(thunk)));


    export default store;

0 个答案:

没有答案