react-router中connect 的泛型和参数

react-router中的connect是连接redux和react组件的数据传输方式,在实际的项目中,typescript和connect联合开发时,connect的参数问题折腾了好久,下面整理的就是参数的具体含义。connect的参数connect([mapStateToProps], [mapDispatchToProps], [mergeProps], [options])...
摘要由CSDN通过智能技术生成

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
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值