为什么要分离 mapDispatchToProps 和 mapStateToProps 的方法?

Why separate methods for mapDispatchToProps and mapStateToProps?

我正在编写一个 redux 应用程序,我 运行 遇到了一个小而烦人的问题。为什么约定将 mapDispatchToProps 和 mapStateToProps 方法分开?为什么不只拥有一个:

mapToProps = (state, dispatch) => {
    ...
}

因为mapDispatchToProps状态改变时不需要重新编译(只调用一次)

如下所述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.

Discussion