繁体   English   中英

TypeError: store.getState is not a function. (In 'store.getState()', 'store.getState' is undefined 我该如何解决这个问题?

[英]TypeError: store.getState is not a function. (In 'store.getState()', 'store.getState' is undefined how can i resolve this problem?

我想 cnnect redux-saga witdh react-native 但这个错误不断发生......

TypeError: store.getState is not a function. (In 'store.getState()', 'store.getState' is undefined

在此处输入图像描述

警告:道具类型失败:提供给Provider的道具store类型function无效,预期object

这是我的代码

  (index.js)


            import {AppRegistry} from 'react-native';
            import Root from './App';
            import {name as appName} from './app.json';

            AppRegistry.registerComponent(appName, () => Root);

(App.js)

    import React from 'react';
    import Store from './store/configureStore'
    import {Provider} from 'react-redux';
    import {App} from './src/index';

    const Root = () => {
      return (
        <Provider store={Store}>
          <App />
        </Provider>
      );
    };

    export default Root;

(来源/index.js)

    import React from 'react';
    import Navigator from './Screens/Navigator';
    import styled from 'styled-components/native';

    const App = ({}) => {
      return (
        <Navigator/>
      );
    };

    export {App};

(商店/cofigurestore.js)

     import { applyMiddleware, createStore, compose } from 'redux';
    import createSagaMiddleware from 'redux-saga';
    import { composeWithDevTools } from 'redux-devtools-extension';

    import reducer from '../reducers';
    import rootSaga from '../sagas';

    const Store = () => {
      const sagaMiddleware = createSagaMiddleware();
      const middlewares = [sagaMiddleware];
      const enhancer = process.env.NODE_ENV === 'production'
        ? compose(applyMiddleware(...middlewares))
        : composeWithDevTools(
          applyMiddleware(...middlewares),
        );
      const store = createStore(reducer, enhancer);
      store.sagaTask = sagaMiddleware.run(rootSaga);
      return store;
    };

    export default Store;

(reducer/index.js)

      import { combineReducers } from 'redux';

      import user from './user';
      import post from './post';

      // (이전상태, 액션) => 다음상태
      const rootReducer = (state, action) => {
        switch (action.type) {
          // case HYDRATE:
          //   // console.log('HYDRATE', action);
          //   return action.payload;
          default: {
            const combinedReducer = combineReducers({
              user,
              post,
            });
            return combinedReducer(state, action);
          }
        }
      };

      export default rootReducer;

(鼠尾草/index.js)

    import { all, fork } from 'redux-saga/effects';
    import axios from 'axios';

    import postSaga from './post';
    import userSaga from './user';



    export default function* rootSaga() {
      yield all([
        fork(postSaga),
        fork(userSaga),
      ]);
    }

请帮帮我…………我想解决这个问题……但我不知道该怎么做

在您的App.js ,您应该将调用Store function 的结果传递给Provider而不是 function 本身。

const Root = () => {
  return (
    <Provider store={Store()}>
      <App />
    </Provider>
  );
};

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM