I just got new project where mostly it uses Redux, i changed my store to use 'configureStore' which comes from redux toolkit and everything works fine, but my reducers and actions are so large that i dont have time to convert those to use 'createslice', my question is in my reducers.ts file where i have all those 'switch' 'cases' can i use 'createslice' also there ? so i want to continue the project with 'createslice' and not convert those older codes to 'createslice' ? is it ok ?
English is not my mother language so could be mistakes.
Example code:
export function articleReducer(
state = initialState,
action: articleReducerAction
) {
switch (action.type) {
case ActionType.GET_A:
return {
...state,
books: action.payload,
};
case ActionType.GET_B:
return {
...state,
libraries: action.payload,
};
}
}
export const articleReducerr= createSlice({
name: "app",
initialState: {
books: [],
libraries: [],
},
reducers: {
GET_C: (state, action) => {
state.books = action.payload;
},
GET_D: (state, action) => {
state.libraries = action.payload;
},
},
});
export const { GET_C, GET_D, } =
articleReducerr.actions;
Yes, you can incrementally convert a project to Redux Toolkit one reducer or one function at a time, and it will all continue to work together. See https://redux.js.org/tutorials/fundamentals/part-8-modern-redux for an example.
(In fact, I work for https://replay.io , and our codebase at https://github.com/RecordReplay/devtools is absolutely a mixture of "modern" and "legacy" Redux patterns!)
That said, I'd definitely recommend trying to migrate more code to createSlice whenever possible.