programing

react-redux-v6:withRef가 삭제됩니다.래핑된 인스턴스에 액세스하려면 연결된 구성 요소의 참조를 사용하십시오.

subpage 2023. 3. 25. 11:06
반응형

react-redux-v6:withRef가 삭제됩니다.래핑된 인스턴스에 액세스하려면 연결된 구성 요소의 참조를 사용하십시오.

연결된 컴포넌트에서 함수를 호출하려면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?

교환이 필요합니다.withRef와 함께forwardRef 다음 릴리즈 노트에 따라 주세요.

withRef접속 옵션이 로 대체되었습니다.forwardRef.한다면{forwardRef : true}에 전달되었습니다.connect연결된 래퍼 컴포넌트에 ref를 추가하면 랩된 컴포넌트의 인스턴스가 실제로 반환됩니다.

고객님의 경우:

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

이 방법은 효과가 있었습니다.

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

언급URL : https://stackoverflow.com/questions/53819335/react-redux-v6-withref-is-removed-to-access-the-wrapped-instance-use-a-ref-on

반응형