18.3.1.2 미들웨어 적용하기
redux-thunk 미들웨어를 설치하고 프로젝트에 적용해 봅시다.
다음 명령어로 라이브러리를 설치하세요.
$ yarn add redux-thunk
스토어를 만들 때 redux-thunk를 적용하세요.
index.js
import React from 'react'; import ReactDOM from 'react-dom'; import { createStore, applyMiddleware } from 'redux'; import { Provider } from 'react-redux'; import './index.css'; import App from './App'; import * as serviceWorker from './serviceWorker'; import rootReducer from './modules'; // import loggerMiddleware from './lib/loggerMiddleware'; import { createLogger } from 'redux-logger'; import ReduxThunk from 'redux-thunk'; const logger = createLogger(); const store = createStore(rootReducer, applyMiddleware(logger, ReduxThunk)); ReactDOM.render( <Provider store={store}> <App /> </Provider>, document.getElementById('root') ); serviceWorker.unregister();