react简书项目学习笔记24redux-thunk中间件实现ajax请求

1.npm install redux-thunk
2.配置文件,store/index.js

import { createStore, compose, applyMiddleware } from 'redux';
import thunk from 'redux-thunk'
import reducer from './reducer';
const composeEnhancers =
  window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ ?
    window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({
    }) : compose;
const enhancer = composeEnhancers(
  applyMiddleware(thunk),
  // other store enhancers if any
);

const store = createStore(reducer, enhancer);
export default store;

3.配置好后,我们就可以在action里写异步代码了

你可能感兴趣的:(react,简书项目,redux-thunk,ajax请求)