【发布时间】:2020-06-25 19:32:03
【问题描述】:
我已经尝试了多种实现,但我似乎无法让状态不是未定义的。我试过箭头函数,我试过在 onChange 事件中绑定它,但似乎没有任何效果。有人可以拿我的代码库给我一些关于我做错了什么的见解吗?谢谢!
import React from 'react';
import {View, Image, StyleSheet} from 'react-native';
import {Button, Text, Input} from 'react-native-elements';
import Icon from 'react-native-vector-icons/FontAwesome';
const styles = StyleSheet.create({
heading: {
padding: 20,
},
});
export default class ContactForm extends React.Component
{
constructor(props)
{
super(props);
this.state = {
name: '',
email: '',
}
}
handleName(e)
{
this.setState({name: e.target.value})
console.log(e.target.value);
}
handleEmail(e)
{
}
submit(e)
{
console.log(this.state.name + " " + this.state.email);
}
render()
{
return (
<View style={styles.heading}>
<Text h5>Sign up to receive updates/newsletters!</Text>
<Input placeholder="your name" onChange={this.handleName.bind(this)} />
<Input placeholder="your email" onChange={this.handleEmail.bind(this)} />
<Button title="Submit" onPress={this.submit}/>
</View>
)
}
}
【问题讨论】:
标签: reactjs react-native react-native-firebase react-native-elements