How to update the state properly inside conditions with redux toolkit?

Viewed 14

Redux toolkit docs doesn't cover the case or I didn't notice.

I have a reducer inside createSlice function:

reducers: {
   addDigit: (state, action) => {
      if (condition) {
         
      }
   }
}

Questions:

  1. I need to use pattern for redux toolkit and then get out of condition like
reducers: {
   addDigit: (state, action) => {
      if (condition) {
         state.current = action.payload
         return                         // <= I NEED RETURN HERE BECAUSE I HAVE ANOTHER CONDITIONS AFTER                   
      }
   }
}

or I need to use classic update pattern for redux (is it good for Immer?):

if (condition) {
   return {
      ...state,
      current: action.payload
   }
}
0 Answers
Related