Created
May 7, 2019 13:39
-
-
Save PavanKu/98f92103af84faaf540aa348cf1a1126 to your computer and use it in GitHub Desktop.
Counter In React native
This file contains hidden or 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 from 'react'; | |
import { View, Text, StyleSheet, TouchableOpacity } from 'react-native'; | |
class Counter extends React.Component { | |
state = { count: 0 }; | |
increment = () => this.setState({count: this.state.count + 1}); | |
decrement = () => this.setState({count: this.state.count - 1}); | |
render() { | |
return ( | |
<View style={styles.container}> | |
<TouchableOpacity onPress={this.decrement}> | |
<Text style={styles.text}>-</Text> | |
</TouchableOpacity> | |
<Text style={styles.text}>{this.state.count}</Text> | |
<TouchableOpacity onPress={this.increment}> | |
<Text style={styles.text}>+</Text> | |
</TouchableOpacity> | |
</View> | |
); | |
} | |
}; | |
const styles = StyleSheet.create({ | |
container: { | |
flexDirection: 'row', | |
borderRadius: 5, | |
borderWidth: 1, | |
borderColor: '#1a91b8', | |
padding: 5, | |
backgroundColor: '#eaf7fd' | |
}, | |
text: { | |
color: '#015169', | |
fontWeight: 'bold', | |
fontSize: 20, | |
padding: 15 | |
} | |
}); | |
export default Counter; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment