我有一些第三方代码,需要能够从外部调用函数
//**Import**
import React from 'react'
// .... etc..
//**function I need to have call the function inside react component**
function showDescription(element) {
// NEED to call function inside component class
this.
}
//**Class Component is here and notice state is set,and onClick had bind**
class SectionE extends React.Component {
constructor(props){
super(props);
this.state = {
visible: false // setting to true will display the modal dialog box
}
this.onClick = this.onClick.bind(this);
}
//**This is the What I want to call from outside!**
onClick() {
this.setState({visible: true}); // show modal dialog
}
//**Mount,calling in here works fine**
componentDidmount() {
//this works as another test
// this.onClick();
}
render()
{
return(
//**Testing calling is works fine (Inside )**
// manually show dialog this works
<button type="button" icon="pi pi-external-link" onClick={this.onClick} classname="btn btn-primary" id="btnImportant">Add Important People</button>
//**3rd party primereact modal dialog**
<Dialog id="modal" header="Important People for ...." visible={this.state.visible} style={{width: '75vw'}} footer={footer} onHide={this.onHide} maximizable>
<ImportantFamily/>
</Dialog>
)
}
}
export default SectionE;
因此我不是要尝试调用的子组件或父组件,而是类组件之外的代码。因此,我什至看不到Ref
将如何工作。
SurveyJS 3rd第三方代码中有很多代码,而我在react组件之外是最大的原因,因为该代码是外部函数。
我有什么选择?