DEV Community

Discussion on: What Even Is A Dispatch Function?

Collapse
 
habibaman766 profile image
Habib Ur Rehman

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

Collapse
 
kelviniot profile image
KelvinIOT • Edited

Hello Habib,

  • So i understand that Store holds the whole state tree of your application.
  • Then you pass to the store, your combineReducer which combines all your separate reducers in an object.
  • When the dispatch function calls the store, it actually tries all your Reducers.
  • But the Reducers listen for events checking for a matching action-type, so if the action-type passed to the dispatch finds a match in a reducer, that particular reducer runs.
Collapse
 
habibaman766 profile image
Habib Ur Rehman

Thank you very much for understanding.

Collapse
 
dustinmyers profile image
Dustin Myers

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 👍👍