HomeOur TeamContact

Counter

By Utkarsh Lubal
Published in Others
July 27, 2022
1 min read
Counter

Table Of Contents

01
Introduction
02
Installation
03
Example
04
Tutorial

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


Previous Article
Progress Steps
Next Article
User Avatar
Utkarsh Lubal

Utkarsh Lubal

Full Stack Developer

Related Posts

Exploring Alternative Emulators for React Native Development
Exploring Alternative Emulators for React Native Development
January 20, 2024
1 min

Quick Links

Advertise with usAbout UsContact Us

Social Media