Created
June 10, 2018 10:34
-
-
Save TheBrown/4d59caa08fe40d2d825ce3aed073146c to your computer and use it in GitHub Desktop.
state example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react'; | |
import { AppRegistry, Text, View } from 'react-native'; | |
class Blink extends Component { | |
constructor(props) { | |
super(props); | |
this.state = {isShowingText: true}; | |
// Toggle the state every second | |
setInterval(() => { | |
this.setState(previousState => { | |
return { isShowingText: !previousState.isShowingText }; | |
}); | |
}, 1000); | |
} | |
render() { | |
let display = this.state.isShowingText ? this.props.text : ' '; | |
return ( | |
<Text>{display}</Text> | |
); | |
} | |
} | |
export default class BlinkApp extends Component { | |
render() { | |
return ( | |
<View> | |
<Blink text='ທົດລອງສະເຕດ' /> | |
</View> | |
); | |
} | |
} | |
// skip this line if using Create React Native App | |
AppRegistry.registerComponent('AwesomeProject', () => BlinkApp); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment