react-router中的connect是连接redux和react组件的数据传输方式,在实际的项目中,typescript和connect联合开发时,connect的参数问题折腾了好久,下面整理的就是参数的具体含义。
connect的参数
connect([mapStateToProps], [mapDispatchToProps], [mergeProps], [options])
connect接收四个参数mapStateToProps, mapDispatchToProps, mergeProps, options
- mapStateToProps: 将redux store中的state映射到当前component, 我们可以在当前组件中使用this.props.stateName,如果没有,为undefined
- mapDispatchToProps: 将redux 中的dispatch方法映射到当前component,如果没有,为undefined
- mergeProps: 合并了上面两个属性的props,默认会assign(mapStateToProps, mapDispatchToProps),所以一般不写,但是如果在当前组件中有有自定义的属性,则需要声明
- options: 可选,一般情况下不填,可以参考官网的描述
[options] (Object) If specified, further customizes the behavior of the connector.
- [pure = true] (Boolean): If true, implements shouldComponentUpdate and shallowly compares the r