Using this code in my configureStore.dev.js file, I get an Uncaught TypeError: getState is not a function
when adding applyMiddleware(reduxImmutableStateInvariant)
. When I remove this added middleware, my project runs fine. What is the proper way to add this middleware? Here is the full file:
import {createStore, compose, applyMiddleware} from 'redux';
import rootReducer from '../reducers';
import reduxImmutableStateInvariant from 'redux-immutable-state-invariant';
export default function configureStore(initialState) {
const store = createStore(rootReducer, initialState, compose(
// Add other middleware on this line...
applyMiddleware(reduxImmutableStateInvariant),
window.devToolsExtension ? window.devToolsExtension() : f => f // add support for Redux dev tools
)
);
if (module.hot) {
// Enable Webpack hot module replacement for reducers
module.hot.accept('../reducers', () => {
const nextReducer = require('../reducers').default; // eslint-disable-line global-require
store.replaceReducer(nextReducer);
});
}
return store;
}
reduxImmutableStateInvariant is a function that you need to call before passing it into applyMiddleware.
const store = createStore(rootReducer, initialState, compose(
// Add other middleware on this line...
applyMiddleware(reduxImmutableStateInvariant()),
window.devToolsExtension ? window.devToolsExtension() : f => f // add support for Redux dev tools
)
);
In the github README docs, is called after being imported (via require) reduxImmutableStateInvariant
. See the third line, below:
// Be sure to ONLY add this middleware in development!
const middleware = process.env.NODE_ENV !== 'production' ?
[require('redux-immutable-state-invariant')(), thunk] :
[thunk];
// Note passing middleware as the last argument to createStore requires redux@>=3.1.0
const store = createStore(
reducer,
applyMiddleware(...middleware)
);
In the thunk middleware, the thunk function is called before it is returned.
const thunk = createThunkMiddleware();
thunk.withExtraArgument = createThunkMiddleware;
export default thunk;
Based on the code, it looks like you can pass in a function (isImmutable
), that is used to determine which properties in your redux state are immutable. I think that providing your own isImmutable function is what allows this middleware to work nicely with other immutable libraries.
export default function immutableStateInvariantMiddleware(isImmutable = isImmutableDefault) {
That method is used here https://github.com/leoasis/redux-immutable-state-invariant/blob/5ed542246e32b7eec06879b25e5a0a478daf4892/src/trackForMutations.js#L5
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With