【发布时间】:2018-01-13 04:48:47
【问题描述】:
我在很多其他地方也看到过这个问题,但出于某种原因,无论我做什么,绑定或声明不同,我都会收到相同的错误,即 _this3.props.toggleProp() 不是函数。 (在 '_this3.props.toggleProp()' 中,'_this3.props.toggleProp 是未定义的。)
我的父组件是:
constructor (props) {
super(props)
this.state = {
selectedTab: 'home',
notificationNumber: -1,
}
this._toggleScreen = this._toggleScreen.bind(this);
this.toggleSchedule = this.toggleSchedule.bind(this);
}
_toggleScreen() {
this.setState({
selectedTab: 'categories',
})
}
render(): React$Element<any> {
function MainContent(props) {
const selectedTab = props.selectedTab;
if (selectedTab === 'home') {
return <Home toggleProp={this._toggleScreen} grain="this one here"/>;
}
if (selectedTab === 'categories') {
return <Categories toggleScreen={this.toggleScreen} />;
}
return <Schedule />;
}
return (
<View style={styles.container}>
<MainContent selectedTab={this.state.selectedTab} style={styles.content}/>
</View>
);
}
}
我的子组件的重要部分是:
render(): React$Element<any> {
return (
<Icon.Button name="home" backgroundColor="rgba(0,0,0,0)" onPress={()=>{this.props.toggleProp()}}>
</Icon.Button>
我有构造函数(道具){ 超级(道具)
在顶部。有什么想法吗?
【问题讨论】:
标签: function reactjs components