【发布时间】:2017-03-20 12:21:34
【问题描述】:
获取不是函数(或)如果我绑定我得到未定义错误的绑定,我应该如何绑定这些传入值的函数?我在这里想念什么..?需要帮助。
子组件:
constructor(props) {
super(props);
this.handler = this.handler.bind(this);
this.state = {
isBoolFlag: true,
}
}
onClick(e){
this.setState({
isBoolFlag: !this.state.isBoolFlag,
});
this.props.handler(!this.state.isBoolFlag); //Error here..
}
render() {
return (
<div>
<a onClick={this.onClick.bind(this)}>
</div>
);
}
}
父组件:
constructor(props) {
super(props);
this.handler = this.handler.bind(this);
this.state = {
showModule: false,
};
}
<div>
{this.state.showModule ? <Child2 /> : <Child1 handler={this.handler} />}
</div>
【问题讨论】:
标签: reactjs react-native redux jsx