可以从外部调用反应组件吗? 例如来自外部的呼叫反应组件
HTML
<div id='react-app'></div>
<button onClick=callReactModal()>PressME</button>
我的分量,我想调用方法
let callReactModal = function() {
console.log('clicked');
//Navigation.sayHello();
}
class Navigation extends React.Component<any, any> {
constructor(props:any){
super(props);
this.state = {
language: {
lang: cookie.load('lang') || ''
}
};
this.click = this.click.bind(this);
}
sayHello =() => {
alert("Hello");
}
}
我不得不从另一个组件调用模态,但我不知道如何实现那。
试图调用方法,更新state
类和获取Warning: setState(...): Can only update a mounted or mounting component.
它需要开放模式(使用语义UI),它采用了先进
handleOpen = (e) => this.setState({
modalOpen: true,
})
modalPart
方法
<Modal size='small' open={this.state.modalOpen} onClose={this.handleClose} trigger={<a className="btn btn-base" onClick={this.handleOpen}>Login</a>} closeIcon='close'>
感谢帮帮我!
你需要定义sayHello'静态',但问题是为什么? – juancab
告诉我'未捕获的ReferenceError:callReactModal没有被定义' –
看在这[[fiddle](https://jsfiddle.net/odzck2a3/) – juancab