Я хочу вызвать функцию из подключенного компонента с помощью 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
Как мне использовать ref в react-redux v6
?
https://github.com/reduxjs/react-redux/releases/tag/v6.0.0
The
withRef
option to connect has been replaced withforwardRef
. If{forwardRef : true}
has been passed toconnect
, adding a ref to the connected wrapper component will actually return the instance of the wrapped component.
Это сработало для меня:
connect(
mapStateToProps,
null,
null,
{
forwardRef: true
}
)
)(ComponentName);