I wanted to ask can't we just simply use handwritten reducer in redux-toolkit as same as we use in redux js And then the rest of all thing I may keep according to tp redux-toolkit in store, but I don't how would I able to give initialState in configureStore please guide me I want to use same reducer function of redux handwritten instead of using createslice
Thank u
CodePudding user response:
You can totally do that, and you can pass preloadedState
into configureStore
(although your hand-written reducer should have it's own "default state", as part of the method signature like function myReducer(state = initialState, action) { ... }
).
But I'd seriously ask you to reconsider. There might be a one-off case where a hand-written reducer has so specific logic that the hand-written reducer actually makes sense, but in 99% of the cases, createSlice
reduces the amount of code (often by a factor of 2-4), and it also makes a lot of common errors like accidentally mutating state impossible (in a hand-written reducer, that is not allowed and considered a bug, in a createSlice
reducer it is totally okay and will lead to an implicit immutable update).
What is the exact reason why you don't want to use createSlice
?