Learning redux? Or useReducer? Then chances are you've been frustrated by the black magic that is the dispatch function 🧙♂️! Well, luckily you hav...
For further actions, you may consider blocking this person and/or reporting abuse
The disptach function calls a reducer function, but i came to know that the control flows in this way.
dispatch -> store -> combineReducer -> reducer
I am not understanding that disptach function is calling the exact reducer function but why the the data is passed to store first then to combineReducer and then to reducer.\
Please can you explain this
Hello Habib,
This is absolutely right! Sorry I was late on the reply. Hopefully kelvin's response helped you understand how this system works with combined reducers. Feel free to reach out if you have any other questions! And thank you Kelvin. That was a great explanation 👍👍
Thank you very much for understanding.
Thank you Dustin, I've been spinning my wheels for more than a week to understand useReducer and at last it makes sense!
Seriously the best kind of reply! Thank you, and I'm glad it was helpful!
Thanks a lot! It's pretty clear and helpful
Thank you! I'm really glad this helped!
If you have multiple reducers, can you tell me how the dispatch function knows which reducer to call?
Is there a switch statement internally with action type as the parameter?
Update: Looking at the source code for createStore it looks like it only ever takes a single reducer? Does that mean you simply use combineReducer() and createStore will choose the correct reducer to use?
Actually when you dispatch an action, it will go through all your reducers that you've "combined". It's the action type that's the magic here. You probably only have one reducer that handles that specific action type. All the other reducers will look at the action type, and return their slice of the state untouched.
Thank you very much. It helped very much. Before reading this I was in confusion but you clear all of my doubts once again thank you very much.
Awesome!! So glad it helped 😊
I came here trying to understand why the actionCreator function can't call the dispatch directly ... why do we have to do
dispatch(actionCreator());
instead of justactionCreator();
I tried, but I could not get away from Redux. So, thanks for this amazingly simple refresher! :)
Thanks Leslie! 😁
it helped :)
Yay!! That makes me so happy!
Thank you. I'm brand new to React and this is helping me grok dispatch and reducers.