この質問は他の多くの場所でも見られましたが、何らかの理由でバインディングや宣言別の方法として、私は_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>
iは、コンストラクタ(小道具){ スーパー(小道具)上部に
を有します。何が起こっているのアイデア?
私はonPressをサポートするreactネイティブを使用しています –