React store.getState is not a function React store.getState is not a function reactjs reactjs

React store.getState is not a function


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.


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.


hope it will help but in my case i got this error because my store was as shown below which is a function:

 const store = preloadedState => {    let initialState={}    //some code to modify intialState       return createStore(reducer, initialState)}

but in index.js i was passing store as a function and not the value it was returning.

wrong

<Provider store={store}>    <MyApp /></Provider>

correct

<Provider store={store()}>    <MyApp /></Provider>