Counter

Published in Others
July 27, 2022
1 min read
Counter

Introduction

Props

Some default props and descriptions.

PropNameDescriptiontypeDefault
minusIf you are not using minusIcon, it shows directly.String-
plusIf you are not using plusIcon, it shows directly.String+
startThe starting numberNumber0
minMinus the minimum selected number.Number0
maxThe most selectable number.Number10
minusIconYou can use it to change the minusIcon.Functionnull
plusIconYou can use it to change the plusIcon.Functionnull
buttonStyleYou can change the types of all buttons.Object{}
buttonTextStyleMinus or plus styles in the buttonObject{}
countTextStylestyles of increasing number.Object{}

Installation

This does't required any special installation of dependacies

Example

-
import React from 'react';
import { View, StyleSheet, Text, TouchableOpacity } from 'react-native';
const styles = StyleSheet.create({
bg: { flex:1, paddingTop: 150, alignItems: 'center', backgroundColor: 'white' },
less: { fontSize: 25, color: '#4d3398', fontWeight: 'bold' },
greater: { fontSize: 25, color: '#f3845c', fontWeight: 'bold' },
button: {
width: 150,
height: 50,
alignItems: 'center',
paddingTop: 10,
borderRadius: 10,
backgroundColor: '#3498db'
},
buttonText: {
fontSize: 25,
color: '#fff'
}
});
class Counter extends React.Component {
state = { count: 0 };
setCount = () => this.setState(
prevState => ({ ...prevState, count: this.state.count + 1 })
)
render() {
const { count } = this.state;
return (
<View style={[styles.bg]}>
<View style={{ height: 100 }}>
<Text style={count < 5 ? styles.less : styles.greater}>You clicked {count} times</Text>
</View>
<View style={{ height: 100 }}>
<TouchableOpacity style={styles.button} onPress={this.setCount}>
<Text style={styles.buttonText}>Click</Text>
</TouchableOpacity>
</View>
</View>
);
}
}
const App = () => (
<Counter />
);
export default App;

Tutorial


Share


Previous Article
Progress Steps
Next Article
User Avatar
Awesome React Native
© 2025, All Rights Reserved.

Social Media