很抱歉,如果这是一个简单的问题,但我似乎无法让它发挥作用。
目前我有一个按钮,应该通过调用onPress函数返回Main(我的应用程序的主页面)。
class Button extends Component{
onTap(){
return <Main/>;
}
render(){
return(
<View>
<TouchableOpacity
onPress={this.onTap}
style={styles.buttonContainer}>
<Text style={styles.buttonText}>LOGIN</Text>
</TouchableOpacity>
</View>
)
}
}
但是我收到了这个错误:
undefined is not a function (evaluating '_this2.props.onTap()')
有人可以帮助我吗?我不知道出了什么问题
答案 0 :(得分:0)
class Button extends Component{
constructor(props) {
super(props);
this.state={isLogin:false}
}
onTap(){
this.setState({isLogin:true});
}
render(){
if(this.state.isLogin){
return <Main/>;
}
return(
<View>
<TouchableOpacity
onPress={this.onTap}
style={styles.buttonContainer}>
<Text style={styles.buttonText}>LOGIN</Text>
</TouchableOpacity>
</View>
)
}};
请先阅读有关JSX的文档〜