React store.getState is not a function

别等时光非礼了梦想. 提交于 2019-12-04 22:52:15

Notice that in your Routes.js the store is not being initialized properly. You should add these lines:

  const initialState = {};
  const store = configureStore(initialState, browserHistory);

as in your index.js file.

I was doing this (a dynamic require) ..

    const store = require('../store/app')
    state = store.getState()

but for some reason when using require instead of import you have to do this ..

    const store = require('../store/app')
    state = store.default.getState()
Steven

This is a typo that generated the error: TypeError: store.getState is not a function

Wrong

const store = createStore(()=>[], {}, applyMiddleware);

Correct

const store = createStore(()=>[], {}, applyMiddleware());

Notice the added parenthesis () on applyMiddleware.

Not sure if this will help but you named your import { Providers } instead of { Provider } from react-redux library.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!