Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Does reducers added via combineReducers use Immer for state updates?

I am a complete newbie in using Redux/Redux Toolkit and am working on writing a small application.
My current store and reducer setup looks something like below:

const store = configureStore({
    reducer: rootReducer
})
  
...
...
const rootReducer = combineReducers({
    settings: SettingsReducer,
    user: UserReducer,
})

I have written SettingsReducer and UserReducer something like below:

const SettingsReducer = (state: SettingsState = initialSettingsState, action: SettingsReducerActionType) => {
    switch (action.type) {
        ...
        ...
        default: return state
    }
}

const UserReducer = (state: UserState = initialUserState, action: UserReducerActionType) => {
    switch (action.type) {
        ...
        ...
        default: return state
    }
}

I would like to know if my UserReducer and SettingsReducer will use Immer for updating state? Looking at the Redux documentation it mentions using functions createSlice and createReducer will allow Immer usage so I wanted to get some confirmation.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

From Redux’s documentation

Redux Toolkit’s createReducer and createSlice automatically use Immer internally to let you write simpler immutable update logic using "mutating" syntax. This helps simplify most reducer implementations.

By not using createReducer and createSlice, you’re not using Immer.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading