2

Not being critical here, I'm just considering deviating from what's clearly a well-established design pattern and I'd like to understand what I'm losing by tossing it.

I understand the role of mapStateToProps, but with mapDispatchToProps it seems that there are a couple significantly simpler options.

One obvious option might be to just reference the global dispatcher singleton from inside of react component callbacks.

Another would be to pass in a bound dispatch function as one of the properties.

Why make a special method for binding dispatch to a component? Something to do with the lifecycle? Does it have some performance or maintainability advantage relative to the obvious alternative options that I mentioned? Is there something this enables us to do which would otherwise be unavailable?

Thanks!

Edit: My question was marked as a duplicate to this SO question which might be sufficient for most people entering similar search queries.

However, I believe my question is more specific and is not covered by the answers in this thread. Specifically, I am wondering why dispatch should be accessed using mapDispatchToProps instead of calling the store.dispatch directly within the callback of a react component.

pixelpax
  • 1,435
  • 13
  • 22
  • 1
    I believe my answer in the linked question deals with the specific question you mentioned, and that topic is followed up in comments. – GreenAsJade May 02 '17 at 02:49

0 Answers0