外部から反応成分を呼び出すことは可能ですか?例えば 外部からの反応成分を呼び出す
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");
}
}
メソッドをコールしたい私は、他のコンポーネントからモーダルを呼び出す必要がありますが、私は達成する方法がわからない私のコンポーネントそれ。
状態
handleOpen = (e) => this.setState({
modalOpen: true,
})
modalPart
を使用しています方法それは(意味-UIを使用して)モーダルを開く必要クラスの更新state
とWarning: setState(...): Can only update a mounted or mounting component.
を取得メソッドを呼び出ししようとすると
<Modal size='small' open={this.state.modalOpen} onClose={this.handleClose} trigger={<a className="btn btn-base" onClick={this.handleOpen}>Login</a>} closeIcon='close'>
ありがとうございます助けて!
あなたはsayHello 'static'を定義する必要がありますが、質問はなぜですか? – juancab
私に「Uncaught ReferenceError:callReactModalは定義されていません」 –
この[fiddle](https://jsfiddle.net/odzck2a3/)を見てください – juancab