来自axios拦截器的redux调度

时间:2020-07-21 03:04:52

标签: reactjs react-redux axios

这是我的商店:

export default function configureStore(preloadedState) {
  const sagaMiddleware = createSagaMiddleware();

  const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;

  const composedEnhancers = composeEnhancers(applyMiddleware(sagaMiddleware));

  const store = createStore(rootReducer, preloadedState, composedEnhancers);
  sagaMiddleware.run(rootSaga);

  return store;
}

这是我的axios实例:

...
import store from "../store/index";
...
myAxios.interceptors.request.use(function (config) {
  store().dispatch({ type: LOADER, payload: { showLoader: true } });
  console.log("request", store().getState())
  return config;
}

看起来像到减速器上了:

...
case LOADER:
      console.log("{ ...state, ...payload }", { ...state, ...payload }) // payload is correct
      return { ...state, ...payload };
...

但是它不会更新状态

0 个答案:

没有答案