Counter

 avatar
unknown
typescript
a year ago
696 B
7
Indexable
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;
Editor is loading...