简体   繁体   中英

Using redux and redux toolkit at same time

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. Seehttps://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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM