我正在使用React.js应用程序,并且我记得我曾经能够通过props将子组件中的回调函数传递给父组件,但是现在我无法再次实现这个功能(我想保持简单,不使用Flux库)。
所以我的父组件是App
:
class App extends Component {
constructor(props) {
super(props);
}
showViewAction(viewToShow){
console.log(viewToShow);
}
render() {
return (
<div>
<AppMenu showView={this.showViewAction}/>
</div>
);
}
}
我的孩子AppMenu
:
class AppMenu extends Component{
constructor(props) {
super(props);
}
showCirculares(){
this.props.showView("circulares");
}
render(){
return(
<div>
<MenuButton onClick={this.showCirculares} buttonTitle="SomeOtherProp"/>
</div>
);
}
}
无论我尝试什么,我总是得到:
在showCirculares中无法读取未定义的属性“props”
我知道这将通过一个简单的任务解决,而且这是基本的React.js内容,只是我找不到解决方案!我做错了什么?
MenuButton
是什么?它是你从库中获取的按钮组件还是自己制作的? - Andrew