Avi*_*ati 13 react-native react-native-android
当我试图为每次按下按钮时设置计数时,我面临上述错误.
export default class ViewIdeas extends Component{
get InitialState(){
return {
count : 0
}
}
render(){
return(
.......
<Button transparent>
<Icon name='ios-thumbs-up-outline' style={{fontSize:21}}
onPress={() => this.setState({count: ++this.state.count})}/>
<Text>{'Like' + this.state.count}</Text>
</Button>
Run Code Online (Sandbox Code Playgroud)
Suh*_*hta 19
请设置这样的状态
constructor(props){
super(props);
this.state = {
count: 0,
}
}
Run Code Online (Sandbox Code Playgroud)
然后你可以做this.state.count
| 归档时间: |
|
| 查看次数: |
14256 次 |
| 最近记录: |