点击name使下面的特点标签改变
import React,{Component} from 'react';
import {View,Text,Image,StyleSheet} from 'react-native';
export default class App extends React.Component{
state={
name:'老曹',
type:'好棒'
}
updateState=()=>{
const type=this.state.type=='开学'?'不开':'开学'
this.setState({type})
}
render(){
const {name,type}=this.state
return(
<View style={styles.container}>
{/* onPress就是点击click事件 */}
<Text onPress={this.updateState}>名称:{name}</Text>
<Text>特点:{type}</Text>
</View>
)
}
}
const styles=StyleSheet.create({
container:{
margin:10
},
})