미들웨어의 기본 구조

const myMiddleware = store => next => action => {
	const result = next(action)  // action 전달
	
	return result  // dispatch(action) 과 같다
}

// index.js
const store = createStore(rootReducer, **applyMiddleware**(myMiddleware))

redux-thunk

npm i redux-thunk

import ReduxThunk from 'redux-thunk'

// index.js
const store = createStore(reducer, coomposeWithDevTools(applyMiddleware(ReduxThunk)))

// thunk 함수
export function thunk() {
	return async (dispatch, getState [,withExtraArgument]) => {  // 액션 함수 반환
		try {
			const res = await axios.get('https:// ~~~')  // 비동기 처리
			dispatch({type: '..', payload: res})  // reducer 에게 액션 전달
		} catch (error) {
				// 에러 처리
			}
	}
}

// container 컴포넌트
dispatch(thunk())

redux-promise

npm i redux-promise

import promiseMiddleware from 'redux-promise'

// index.js
const store = createStore(rootReducer, applyMiddleware(promiseMiddleware))

// 액션 생성자
export const async getInfo() {
	const res = await axios.get('~~')  // 비동기 처리. data는 promise 객체
	return { type: '..', payload: res.data }  // 액션 반환
}