2 8*_*2 8 24 javascript reactjs redux react-redux
我想使用ref从连接组件调用一个函数,所以我之前withRef: true
在连接组件中使用过:
export default connect(
mapStateToProps,
mapDispatchToProps, null, {withRef: true})(InviteReceiverForm)
Run Code Online (Sandbox Code Playgroud)
并在表示部分:
<ExampleComponent ref={
cmp => { if (cmp) { this.invdividualSenderFormRef = cmp.getWrappedInstance() } } />
Run Code Online (Sandbox Code Playgroud)
更新到react-redux
6后,我收到此错误:
withRef is removed. To access the wrapped instance, use a ref on the connected component
Run Code Online (Sandbox Code Playgroud)
如何在react-redux 6中使用ref?
Ian*_*emp 37
https://github.com/reduxjs/react-redux/releases/tag/v6.0.0
在
withRef
连接选项已被替换forwardRef
.如果{forwardRef : true}
已传递给connect
,则向连接的包装器组件添加ref实际上将返回包装组件的实例.
小智 5
这对我有用:
connect(
mapStateToProps,
null,
null,
{
forwardRef: true
}
)
)(ComponentName);
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
10347 次 |
最近记录: |