The object notation for `createSlice.extraReducers` is deprecated, and will be removed in RTK 2.0. Please use the 'builder callback' 해결

김서연·2022년 11월 29일
0

Project

목록 보기
3/3

리듀서를 작성하고 나니, 경고메세지가 나왔다.

'createSlice.extraReducers'에 대한 객체 표기법은 더 이상 사용되지 않으며 RTK 2.0에서 제거될 예정입니다. 대신 '빌더 콜백' 표기법을 사용하세요.'

링크로 들어가서 빌더콜백에 대해 찾아봤다.
https://redux-toolkit.js.org/api/createSlice

원래 작성

const livingRoomSlice = createSlice({
  name: "livingRoom",
  initialState: {
    livingRoomInitial: {},
    loading: false,
    error: "",
  },
  reducers: {},
  extraReducers: {
    [getLivingRoom.fulfilled]: (state, action) => {
      state.livingRoomInitial = action.payload;
      state.loading = true;
      state.error = "";
    },
  },
});

빌더콜백 적용 후

const livingRoomSlice = createSlice({
  name: "livingRoom",
  initialState: {
    livingRoomInitial: {},
    loading: false,
    error: "",
  },
  reducers: {},
  extraReducers: (builder) =>
    builder
      .addCase(getLivingRoom.fulfilled, (state, action) => {
        state.livingRoomInitial = action.payload;
        state.loading = true;
        state.error = "";
      }),
});

이렇게 바꿔주니 에러 해결!~

profile
프론트엔드 엔지니어로 성장

0개의 댓글