react-redux-v6: withRef is removed. To access the wrapped instance, use a ref on the connected component

Viewed 22612

I want to call a function from a connected component using ref, so I used before from withRef: true in connected component:

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

and in the presentational component:

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

But after I updated to react-redux v6, I got this error:

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

How can I use ref in react-redux v6?

2 Answers

This worked for me:

connect(
    mapStateToProps,
    null,
    null,
    {
      forwardRef: true
    }
  )
)(ComponentName);
Related