본문 바로가기
tech documents/react

react-redux undefined 문제

by kimtahen 2022. 2. 26.
반응형

서론

express.js + react.js 를 사용한 server-side-rendering 으로 블로그를 제작중이다. react.js 에 redux를 사용해서 data를 전달하기 위해서 서버와 클라이언트에 redux를 추가하던 중 아래와 같은 문제가 생겼다.

The slice reducer for key "category" returned undefined during initialization. If the state passed to the reducer is undefined, you must explicitly return the initial state. The initial state may not be undefined. If you don't want to set a value for this reducer, you can use null instead of undefined.

결국 reducer에 default case를 추가해주지 않아서 발생한 문제이다.

해결법

reducer에 default case인 경우 state를 반환하도록 아래와 같이 추가해준다.

반응형

댓글