问题
Typically I do the following types of things from a Parent component
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>
Notice above I have SectionZ
which is the child component.. I have function inside handleTabs={this.handleTabs}
and I also have ref={(secZComponent) => {window.secZComponent.handleTabs() = secZComponent}}
which I have used in the past to allow for some json rendered form data to be able to call a function
Seems that I cannot call parent from the child with either handleTabs={this.handleTabs} or window..... since it is outside the
class component --> class SectionZ extends React.Component { }
来源:https://stackoverflow.com/questions/59166100/call-react-parent-component-function-from-outside-of-the-child-component-class