Reducers !== Actions #5205
Replies: 5 comments
-
|
if the action truly has no "home" slice, you can use the lower level |
Beta Was this translation helpful? Give feedback.
-
I'm not sure I understand the intent of this sentence :) Taking a step back: if you look at early Redux code, there are 3 things you typical wrote:
The main point of
so at that point the only thing you have to write is the.... "reducers"! and thus the field is named "reducers". We then generate the action creators. So, input "reducers" -> output "actions", derived and generated. The other insight here is that as Ben said, historically there's almost always been a 1:1 correspondence between an action and how many reducers actually listen for that action to do an update. So, we optimize for that case. Write a slice, write a reducer like |
Beta Was this translation helpful? Give feedback.
-
This might be a misconception. A slice results in one externally accessible reducer that handles multiple actions. What you see in |
Beta Was this translation helpful? Give feedback.
-
|
Ah, thanks everyone. One reason I were asking this, is that I used Redux 6–7 years ago using the old And now I am coming back, questioning the recent changes (I might be wrong and am grateful for this discussion) 🙇🏼♂️ reducers: {
addTodo: {
reducer: (state, action: PayloadAction<Item>) => { //<--- Action mentioned here
state.push(action.payload)
},
...
},
},What comes first? An action or reducing state? Chicken or eggs? In the above I believe an egg (= state) comes first. Without an egg, there can't be a chick (but the question still remains, who created the egg first) 😅 That said, about the other comments:
... and ...
Awesome job. I am impressed and like it. Must have been hard work. Perhaps naming is the issue here? Because ...
... because we developers tick in user actions first, before state changes. Press the Add TODO button first. So, having it action-oriented first before reducers might welcome more developers, perhaps? Just continuing the conversation. I don't have an answer nor solution for that now. Cheers. |
Beta Was this translation helpful? Give feedback.
-
|
All sorted, the other discussion clarified this. Closing this discussion now. Thanks, all. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello folks - sorry, it's me again :)
The wonderful
createSlicefunction takes inreducersas a parameter, thenthe return object has those reducers under
actionsI think we shouldn't mix up reducers with actions.
IMO reducers are great for reducing complexity, while actions are more user-oriented. Not the same thing. Thoughts?
Beta Was this translation helpful? Give feedback.
All reactions