我想使用以下答案
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'))
)


但我不明白这里的javascript语法
他如何使用compose(argument)(createStore)(argument)

还有像createStore(reducer,initialState,compose(argument))这样的替代方法吗?

另外,初始状态如何传递到这里

const createStoreWithMiddleware = compose(
  applyMiddleware(thunkMiddleware)
)(createStore);

export default function configureStore(initialState) {
  const store = createStoreWithMiddleware(rootReducer);
  return store;
}

最佳答案

是! enhancer()(createStore)语法是使用createStore的较旧的方式,我们正在尝试鼓励人们使用较新的语法:

const composedEnhancers = compose(
    firstEnhancer,
    secondEnhancer
);

const store = createStore(
    rootReducer,
    preloadedState,
    composedEnhancers
);

10-08 14:38