React & React Native Component
컴포넌트(Component)
- 재사용이 가능한 조립 블록, 화면에 나타나는 UI 요소
- 부모로부터 받은 속성(Props)나 자신의 상태(State)에 따라 표현이 달라지고 다양한 기능을 수행
- (내장 컴포넌트)
https://reactnative.dev/docs/components-and-apis (View, Text 등)
Core Components and APIs · React Native
React Native provides a number of built-in Core Components ready for you to use in your app. You can find them all in the left sidebar (or menu above, if you are on a narrow screen). If you're not sure where to get started, take a look at the following cat
reactnative.dev
https://reactnative.dev/docs/button
Button · React Native
A basic button component that should render nicely on any platform. Supports a minimal level of customization.
reactnative.dev
import { StatusBar } from 'expo-status-bar';
import { StyleSheet, Text, View, Button } from 'react-native';
export default function App() {
const name = "IRONMAN";
const age = 100;
return (
<View
style = {{
flex: 1,
backgroundColor: '#fff',
alignItems: "center",
justifyContent: "center",
}}
>
<Text style = {{fontSize: 30, marginBottom: 10}}>Button Component</Text>
<Button title = "Button" onPress = {() => {alert("Click!!!!")}}></Button>
</View>
);
}
https://reactnative.dev/docs/button#color
Button · React Native
A basic button component that should render nicely on any platform. Supports a minimal level of customization.
reactnative.dev
- (커스텀 컴포넌트)
import React from "react";
import {Text, TouchableOpacity} from 'react-native';
const MyButton = () => {
return (
<TouchableOpacity>
<Text style = {{fontSize: 24}}>My Button</Text>
</TouchableOpacity>
);
};
export default MyButton ;
import { StatusBar } from 'expo-status-bar';
import { StyleSheet, Text, View, Button } from 'react-native';
import MyButton from './src/MyButton'
export default function App() {
return (
<View
style = {{
flex: 1,
backgroundColor: '#fff',
alignItems: "center",
justifyContent: "center",
}}
>
<Text style = {{fontSize: 30, marginBottom: 10}}>My Button Component</Text>
<MyButton></MyButton>
{/* <Button title = "Button" onPress = {() => {alert("Click!!!!")}}></Button> */}
</View>
);
}
- TouchableOpacity 컴포넌트: https://reactnative.dev/docs/touchableopacity
TouchableOpacity · React Native
If you're looking for a more extensive and future-proof way to handle touch-based input, check out the Pressable API.
reactnative.dev
- TouchableWithoutFeedback 컴포넌트: https://reactnative.dev/docs/touchablewithoutfeedback
TouchableWithoutFeedback · React Native
If you're looking for a more extensive and future-proof way to handle touch-based input, check out the Pressable API.
reactnative.dev