如何正确安装使用redux-thunk

首先下载redux-thunknpm install redux-thunk --save
然后在创建store的地方使用

import { createStore, applyMiddleware, compose } 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)
);

const store = createStore(reducer, enhancer);

export default store;

如果没有报错就表示正确使用了!!

你可能感兴趣的:(react)