Skip to content

Instantly share code, notes, and snippets.

@PavanKu
Created May 7, 2019 13:39
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 PavanKu/98f92103af84faaf540aa348cf1a1126 to your computer and use it in GitHub Desktop.
Save PavanKu/98f92103af84faaf540aa348cf1a1126 to your computer and use it in GitHub Desktop.
Counter In React native
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