react-redux-v6: withRef 被移除。要访问包装的实例,请在连接的组件上使用 ref

Posted

技术标签:

【中文标题】react-redux-v6: withRef 被移除。要访问包装的实例,请在连接的组件上使用 ref【英文标题】:react-redux-v6: withRef is removed. To access the wrapped instance, use a ref on the connected component 【发布时间】:2019-05-18 01:30:16 【问题描述】:

我想使用ref从连接组件调用函数,所以我之前在连接组件中使用了withRef: true

export default connect(
  mapStateToProps, mapDispatchToProps, null, withRef: true
)(InviteReceiverForm)

在演示组件中:

<ExampleComponent 
  ref= cmp =>  if(cmp)  this.individualSenderFormRef = cmp.getWrappedInstance()  />

但是在我更新到react-redux v6之后,我得到了这个错误:

withRef is removed. To access the wrapped instance, use a ref on the connected component

如何在react-redux v6 中使用 ref?

【问题讨论】:

【参考方案1】:

https://github.com/reduxjs/react-redux/releases/tag/v6.0.0

withRef 连接选项已替换为 forwardRef。如果forwardRef : true 已传递给connect,则向连接的包装组件添加引用实际上将返回被包装组件的实例。

【讨论】:

【参考方案2】:

这对我有用:

connect(
    mapStateToProps,
    null,
    null,
    
      forwardRef: true
    
  )
)(ComponentName);

【讨论】:

以上是关于react-redux-v6: withRef 被移除。要访问包装的实例,请在连接的组件上使用 ref的主要内容,如果未能解决你的问题,请参考以下文章

Oracle 树上的逻辑

PostgreSQL 分析函数窗口化以查找列中的下一个值

查找可被 6 或 7 整除但不能同时被 6 或 7 整除的整数

一直被用错的6种SQL 错误用法

Gitlab,权限被拒绝(公钥),版本 6-4 稳定

入职 6 个月,被裁员。。