Reputation: 8702
I'm writing a redux app and I ran in to a small but nagging question. Why is the convention to separate the mapDispatchToProps and mapStateToProps methods? Why not just have one:
mapToProps = (state, dispatch) => {
...
}
Upvotes: 5
Views: 247
Reputation: 3067
As mentioned in below link
The separation exists for performance reasons: mapStateToProps and mapDispatchToProps are separate for a good reason, consider the performance: mapStateToProps is actually run several times when state changes, and mapDispatchToProps once (or way fewer anyway than mapStateToProps) it doesn't depend on the state.
Upvotes: 0
Reputation: 44609
Because the mapDispatchToProps
doesn't need to be recompiled when the state change (it's only called once).
Upvotes: 6