score:8

Accepted answer

@Andrey Prokhorov is right, and it's funny you asked. I found myself in the bowels of github issues earlier today and found this issue (Add state as the third parameter to mapDispatchToProps). While the title doesn't seem to relate, if you dig through the comments, gaearon (the creator of react-redux) explains:

Please take a look at #1. This option has been considered and rejected. Yes, it's very bad for performance to re-bind action creator on every dispatch, which is what will happen if we let people access the state in the same place they bind action creators. Technically they can still do it now with mergeProps but it's hidden well enough that people who aren't experienced with Redux don't discover it by mistake.

I also linked to the very first issue that gaearon linked to for react-redux where it was discussed (it was literally issue #1 on github for react-redux). I'm sure they COULD change it to the way you describe, but I think gaearon's comment sums it up:

The goal of this library is to encourage performant patterns because otherwise people will say “Redux is slow!” even if the cause is their suboptimal function binding code. We don’t want this to happen, so we’d rather make certain unperformant cases harder to implement.


Related Query

More Query from same tag