Counter

mail@pastecode.io avatar
unknown
typescript
7 months ago
696 B
4
Indexable
Never
import React, { useState, useEffect } from 'react';
import { View, Text, Button } from 'react-native';

const CounterApp = () => {
  const [count, setCount] = useState(0);

  useEffect(() => {
    if (count === 3) {
      alert('Count reached 3!');
    }
  }, [count]);

  const incrementCount = () => {
    setCount(count + 1);
  };

  const resetCount = () => {
    setCount(0);
  };

  return (
    <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
      <Text style={{ fontSize: 24 }}>Count: {count}</Text>
      <Button title="Increment" onPress={incrementCount} />
      <Button title="Reset" onPress={resetCount} />
    </View>
  );
};

export default CounterApp;