我也見過這個問題很多其他地方,但由於某種原因,無論我做什麼,綁定或聲明不同的是,我不斷收到_this3.props.toggleProp()不是函數的錯誤。 (在 '_this3.props.toggleProp()',「_this3.props.toggleProp是不確定的)作爲一個道具反應本地傳遞函數作爲子組件(this.props.functionName不是一個函數)
我的父組件是:
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>
我有構造(道具){ 超級(道具)
在頂部。任何想法發生了什麼?
我正在使用react native支持onPress –