STUDY/Front
React-native #2) State란?
CEHON YUJUNG
2021. 7. 22. 12:05
State란 글로벌 변수같은 것
예제
class App extends Component{
constructor(props) {
super(props);
this.state = {
address : ''
}
}
writeAddress = () => {
this.setState({
address : "경기도 수원시"
}, function(){
alert('주디얌');
})
}
writeReset = () => {
this.setState({
address : ""
})
}
render(){
return (
<View style = {styles.container}>
<Text style = {styles.hello}>SPONGE 화이팅하자구</Text>
<JUDY type = 'one'/>
<JUDY type = 'two'/>
<Text> {this.state.address}</Text>
<Button title = {'나의 주소 출력'} onPress={this.writeAddress}/>
<Button title = {'리셋'} onPress={this.writeReset}/>
</View>
);
}
};
반응형