gpt4 book ai didi

javascript - 在我用 injectIntl​​ 包装它之后丢失了 react 组件 ref

转载 作者:行者123 更新时间:2023-11-29 10:31:34 26 4
gpt4 key购买 nike

在用 injectIntl​​ 包装 React 组件后,我在获取对函数的引用时遇到了问题。基本上我需要的是通过 ref 访问组件中的 func这就是我正在做的

class MainContainer extends React.Component {
constructor(props) {
super(props);
}

getSamples(){
return sth
}

render() {
return (<div>this.props.sth</div>)
}

export default injectIntl(MainContainer )

在用 injectIntl​​ 包装后,是否有可能获得对 MainContainer 的引用?

最佳答案

应传递 withRef 选项。

export default injectIntl(MainContainer,{ withRef: true })

可以使用以下方法检索 MainContainer 包装器组件实例

<MainContainer ref={c => { this.container = c; }} />

包装的组件实例可以使用

this.container.getWrappedInstance();

关于javascript - 在我用 injectIntl​​ 包装它之后丢失了 react 组件 ref,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44805939/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com