본문 바로가기

프로그래밍

[react native] 카운터 앱

반응형
import { StatusBar } from 'expo-status-bar';
import React, { useState } from 'react';
import { StyleSheet, Text, View, Button } from 'react-native';


export default function App() {

  const [cnt, setCnt] = useState(10); 



  return (
    <View style={styles.container}>
      <Text style={styles.assa}>헬로우 리엑트 네이티브</Text>
      <Text style={styles.cnt}>{cnt}</Text>
      <Button title="더하기" onPress={  () => setCnt(cnt+1)  }></Button>
      <Button title="빼기" onPress={  () => setCnt(cnt-1)  }></Button>
      <StatusBar style="auto" />
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    alignItems: 'center',
    justifyContent: 'center',
  },
  assa:{
    color:'#f00', 
    fontSize:20, 
  },
  cnt:{
    fontSize:50, 
    marginTop:20, 
  }

});
반응형