I want to use the following answer Redux state persistence with a database
import {createStore, compose, applyMiddleware} from 'redux';
const localStorageMiddleware = ({getState}) => {
return (next) => (action) => {
const result = next(action);
localStorage.setItem('applicationState', JSON.stringify(
getState()
));
return result;
};
};
const store = compose(
applyMiddleware(
localStorageMiddleware
)
)(createStore)(
reducer,
JSON.parse(localStorage.getItem('applicationState'))
)
But I didn't understand the javascript syntax here
How he used compose(argument)(createStore)(argument)
?
is there any alternative like createStore(reducer,initialState,compose(argument))
?
Also, how is initial state will be passed here
const createStoreWithMiddleware = compose(
applyMiddleware(thunkMiddleware)
)(createStore);
export default function configureStore(initialState) {
const store = createStoreWithMiddleware(rootReducer);
return store;
}