我有一個點擊,調用setmenu函數(在className =「菜單」列表中),但我不想在我的3個不同的回報中重複它。相反,我想把它放到它自己的函數/組件中,並調用它3次。處理單擊返回外部
但是,當我移動它的點擊無法找到setmenu了,儘管我仍然有this.setmenu = this.setmenu.bind(this);在構造函數中?
setmenu(event, value){
this.setState({showForm: value});
console.log(this.state.showForm, "this.state.showForm")
}
render() {
const showForm = this.state.showForm;
if (showForm === 1){
return (
<div>
<ul className="menu">
<li><a href="javascript:void(0)" onClick={e => this.setmenu(e, 1)}>Form 1</a></li>
<li><a href="javascript:void(0)" onClick={e => this.setmenu(e, 2)}>Form 2</a></li>
<li><a href="javascript:void(0)" onClick={e => this.setmenu(e, 3)}>Form 3</a></li>
</ul>
<FacebookLoginForm value={this.state.facebookResponse} />
</div>
);
}
else if(showForm === 2) {
return (
<div>
<ul className="menu">
<li><a href="javascript:void(0)" onClick={e => this.setmenu(e, 1)}>Form 1</a></li>
<li><a href="javascript:void(0)" onClick={e => this.setmenu(e, 2)}>Form 2</a></li>
<li><a href="javascript:void(0)" onClick={e => this.setmenu(e, 3)}>Form 3</a></li>
</ul>
<ManualLoginForm />
</div>
);
}
else if (showForm === 3){
return (
<div>
<ul className="menu">
<li><a href="javascript:void(0)" onClick={e => this.setmenu(e, 1)}>Form 1</a></li>
<li><a href="javascript:void(0)" onClick={e => this.setmenu(e, 2)}>Form 2</a></li>
<li><a href="javascript:void(0)" onClick={e => this.setmenu(e, 3)}>Form 3</a></li>
</ul>
<ManualRegForm />
</div>
)
}
}