从子组件类外部调用React Parent组件函数

通常,我从父组件执行以下类型的操作

   this.childZ = React.createRef();  // 

   this.handletabs = this.handletabs.bind(this);  // bind a function 

   //actual function in the parent class component 
   handletabs = () => { ...}  // I want to call this from Child Component - but outside the class (i have 3rd party javascript etc..

   //In my render()   

   <Tab eventKey={19} title="CORE SEC Z."><SectionZ ref={(secZComponent) => {window.secZComponent.handletabs() = secZComponent}} handletabs={this.handletabs} ref={this.childZ}/></Tab> 

上面的通知中我有SectionZ这是子组件。我在handletabs={this.handletabs}中有函数 而且我也有ref={(secZComponent) => {window.secZComponent.handletabs() = secZComponent}},我过去曾经使用它来允许一些json呈现的表单数据能够调用函数

似乎我无法使用handletabs = {this.handletabs}或window .....从孩子那里叫父母,因为它不在 类组件-> class SectionZ extends React.Component { }

shuyongzhi 回答:从子组件类外部调用React Parent组件函数

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/2982071.html

大家都在问