Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- .env
- 코드정렬
- 자동완성방지
- useReducer
- interactive_timeout
- dotenv
- 리액트
- 자연수 뒤집어 배열로 만들기
- prettier
- 프리티어
- 프로그래머스
- next #middleware
- Node
- react
- 코딩테스트
- vscode
- axios
- EC2
- reacts3
- AWS
- MySQL
- utf8mb4
- 커밋 한번에
- express
- max_allowed_packet
- 리액트코드정렬
- 제일 작은 수 제거하기
- s3확장자
- 부족한 금액 계산하기
- elasticIP
Archives
- Today
- Total
Sungtt
[Next.js@13] Next + RTK 적용중 오류...Prefer to use the callback notation for the middleware option in configureStore to access a pre-typed getDefaultMiddleware instead. 본문
React
[Next.js@13] Next + RTK 적용중 오류...Prefer to use the callback notation for the middleware option in configureStore to access a pre-typed getDefaultMiddleware instead.
sungtt 2022. 12. 24. 05:36[Next.js@13] Next + RTK 적용중 오류...
Prefer to use the callback notation for the middleware option in configureStore to access a pre-typed getDefaultMiddleware instead.
기본 미들웨어를 불러오는 getDefaultMiddleware 함수가 더 이상 사용되지 않고, 콜백으로 대체되었다고 한다.
오래전에 PR된 내용이었다. 이전의 코드는 아래와 같이 getDefaultMiddleware을 import하여 사용했다.
// store.ts
import {
configureStore,
AnyAction,
Reducer,
getDefaultMiddleware
} from '@reduxjs/toolkit';
// ### store 생성 함수
const makeStore = () => {
// 미들웨어 추가
const middleware = getDefaultMiddleware();
if (process.env.NODE_ENV === 'development') { // 개발환경에서 logger 미들웨어 추가
middleware.push(logger);
}
// store 생성
const store = configureStore({
reducer: rootReducer as Reducer<ReducerStates, AnyAction>,
middleware, // 미들웨어
});
// store 반환
return store;
};
현재 사용법은 아래와 같다.
더 이상 getDefaultMiddleware을 import할 필요 없으며
configureStore의 두번째 인자로 middleware의 인자에 들어있다.
RTK 문서에 따르면 middleware를 사용할 때 구조분해할당보다는 concat이나 prepend를 추천한다고한다.
// store.ts
import {
configureStore,
AnyAction,
Reducer,
} from '@reduxjs/toolkit';
const makeStore = () => {
const store = configureStore({
reducer: rootReducer as Reducer<ReducerStates, AnyAction>,
middleware: (getDefaultMiddleware) => {
if (process.env.NODE_ENV === 'development') {
// return [...getDefaultMiddleware,logger] // 비추천
return getDefaultMiddleware().concat(logger); // 개발환경에서 logger 미들웨어 추가
} else {
return getDefaultMiddleware();
}
},
devTools: process.env.NODE_ENV === 'development', // 개발자도구
});
return store;
};
https://github.com/reduxjs/redux-toolkit/pull/1258
🗑 📝 Deprecate getDefaultMiddleware export by Shrugsy · Pull Request #1258 · reduxjs/redux-toolkit
Mark getDefaultMiddleware as deprecated Docs: replace usage of gDM imports with callback notation Docs: remove references to gDM export Fix console warning on Automated Refetching page
github.com
'React' 카테고리의 다른 글
[Next.js@13] jwt 라이브러리, jsonwebtoken 대신 jose (0) | 2022.12.27 |
---|---|
[Next.js@13] redirect와 cookie 설정 한번에 하기 (0) | 2022.12.27 |
[Next.js@13] Next에서 mysql 연동하기 (0) | 2022.12.22 |
[Next.js@13] API Routes 사용하기 (0) | 2022.12.21 |
[Next.js@13] middleware.ts 미들웨어 사용하기 (0) | 2022.12.21 |
Comments