하나의 웹 애플리케이션에 수백개의 action이 만들어지는데, 이를 console로 확인하기엔 어려움이 있어서
실제 데이터가 어떻게 흘러하는지 파악하는 로거 미들웨어를 만들어보고자 한다.
다음과 같이 작성할 수 있다.
여기서 next는 dispatch로 생각하면 된다
export const logger = store => next => action => {
next(action)
}
사용할 때는 ..
const store = createStore(reducer, [logger]);
실제로 로그를 남겨보자!
export const logger = store => next => action => {
const currentState = store.getStore();
console.groupCollapsed('action logger = ', action.type); // 한번 클립으로 접기
console.log('currentState : ', currentState);
console.log('action payload : ', action.payload);
console.groupEnd();
next(action)
}
'Redux 공식 홈페이지 따라하기' 카테고리의 다른 글
Redux 따라 만들어보기 (8) - 비동기 처리기 미들웨어 (0) | 2025.01.29 |
---|---|
Redux 따라 만들어보기 (6) - 한계점 돌파 (0) | 2025.01.29 |
Redux 따라 만들어보기 (5) - 비동기와 동기 (0) | 2025.01.28 |
Redux 따라 만들어보기 (4) - 리팩토링 (0) | 2025.01.28 |
Redux 따라 만들어보기 (3) - 실전편 (0) | 2025.01.28 |