Getting error: TypeError: store.getState is not a function
gullerg opened this issue · 1 comments
gullerg commented
Followed the docs and updated my code from:
const bindMiddleware = (middleware) => {
if (process.env.NODE_ENV !== 'production') {
const { composeWithDevTools } = require('redux-devtools-extension')
return composeWithDevTools(applyMiddleware(...middleware))
}
return applyMiddleware(...middleware)
}
...
const initStore = () => createStore(reducer, bindMiddleware([thunkMiddleware]))
export const wrapper = createWrapper(initStore)
to:
const bindMiddleware = (middleware) => {
if (process.env.NODE_ENV !== 'production') {
const { composeWithDevTools } = require('redux-devtools-extension')
return composeWithDevTools(applyMiddleware(...middleware))
}
return applyMiddleware(...middleware)
}
...
const initStore = () => wrapMakeStore(() =>
createStore(reducer, bindMiddleware([thunkMiddleware, nextReduxCookieMiddleware({ subtrees: ["auth"] })]))
)
export const wrapper = createWrapper(initStore)
The code works as expected before making the change; however, after the change, I get the following error: TypeError: store.getState is not a function. How can this be resolved?
bjoluc commented
const initStore = () => wrapMakeStore(() =>
should be
const initStore = wrapMakeStore(() =>
wrapMakeStore
is supposed to wrap your initStore
function, which is called makeStore
in the next-redux-wrapper usage section.