Skip to content

Instantly share code, notes, and snippets.

@TheBrown
Created June 10, 2018 10:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TheBrown/4d59caa08fe40d2d825ce3aed073146c to your computer and use it in GitHub Desktop.
Save TheBrown/4d59caa08fe40d2d825ce3aed073146c to your computer and use it in GitHub Desktop.
state example
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