<๊ฐ์>
props๋ ์์ ์ปดํฌ๋ํธ์์ ๋ฐ์ ์์ฑ๊ฐ๋ค์ ํ์ ์ปดํฌ๋ํธ์ ์ ๋ฌํด์ฃผ๋ ๊ฐ์ฒด์ด๋ค.
์์ ์ปดํฌ๋ํธ์์ ๋ฐ์ ์์ฑ ๊ฐ๋ค์ props์ ๋ฉค๋ฒ๋ก ๋ค์ด๊ฐ๋ค.
์นดํก ํ๋กํ์ ๋ด ํ๋กํ์ด๋ , ์น๊ตฌ๋ค ํ๋กํ์ด๋ ๋ก์ง์ด ๊ฐ๋ค.
๋ฐ๋ผ์ ์นดํก ํ๋กํ ํ๋ํ๋ ํ์ ์ปดํฌ๋ํธ๋ก ๋ง๋ค์ด ๋ฒ๋ฆฌ๋ฉด, ์ค๋ณต์ฝ๋๊ฐ ๋ง์์ ธ์ ๊ฐ๋ ์ฑ์ด ๋จ์ด์ง๋ค.
์ด๋ฅผ ์ํด ํ๋กํ ๋ก์ง์ ํ๋๋ง ๋ง๋ค๊ณ , ๊ฐ ํ๋กํ๋ง๋ค ๋ค๋ฅธ ์ธ์ ๊ฐ๋ค์ props๋ก ๋๊ฒจ ๋ฐ์ ๋ง๋๋ ๊ฒ์ด
ํจ์ฌ ํจ์จ์ ์ด๋ค.
์ฌ๊ธฐ์ ํด๋ณผ ๊ฒ์ ํ๋์ ํ๋กํ ๋ก์ง์ ๋ง๋ค๊ณ , ํ๋กํ ๋ณ๋ก ๋ค๋ฅธ ๊ฐ๋ค์ props๋ก ๋ฐ์์ ๊ตฌํํ ๊ฒ์ด๋ค.
ํ์ ์ปดํฌ๋ํธ๋ฅผ ์ ์ธํ ๋ถ๋ถ๊ณผ ํธ์ถํ ๋ถ๋ถ์ด ๋ฐ๋ก ๋๋๋ ๊ฑธ ๋ณผ ์ ์๋ค.
ํธ์ถํ ๋ถ๋ถ์์ ๋ฐ์ ์์ฑ ๊ฐ๋ค์ props๊ฐ ๋ฉค๋ฒ๋ก ๋ฐ์์ ์ ์ธ ๋ถ๋ถ์ ์ ๋ฌํด์ค๋ค.
1. ์ฝ๋ ๋ฆฌ๋ทฐ
import React from 'react';
import { Image, ScrollView, StyleSheet, View, Text } from 'react-native';
/**
* Header
* MyProfile
* Division
* FriendSection
* FriendList
*/
const Header = (props) => {
return <Text>{props.title}</Text>
}
//๋ณ๋์ฌํญ์ธ ์ด๋ฆ, ์นดํกํ๋กํ, ํ๋กํ ์ฌ์ด์ฆ๋ ์์ฑ์ผ๋ก ์จ์ props๋ก ๋ณด๋.
const MyProfile = () => {
return <Profile
name="์๋ฏผ"
uri="https://www.sisain.co.kr/news/photo/202110/45791_82634_4851.jpg"
profileSize={40}
/>;
}
const Division = () => {
return <Text> Division</Text>
}
const FriendSection = () => {
return <Text> FriendSection</Text>
}
const FriendList = () => {
return (
<View>
<Profile
name="๋ช
ํ"
uri="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcT0Yr6EHXBuyFT758YQZJIfRS-OxlHLe_xLpmjfq51POfIrnezVU4RRjEPUrbxCI-62hqo&usqp=CAU"
profileSize={30}
/>
<Profile
name="๋ฏผํ"
uri="https://cdn.healthinnews.co.kr/news/photo/202204/29034_29822_2928.jpg"
profileSize={30}
/>
<Profile
name="์๋ก"
uri="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQhPp9xC6b6117NcTAyvXr5rw0jwhBp-l3_CrjegZByjEzObtv0AXEbgy8LvorDqf3CKmI&usqp=CAU"
profileSize={30}
/>
<Profile
name="์ฌ์ฑ"
uri="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ9-fJsY_Vm3jmGZh0ZRdIW6c8xcGfNkfhHkpKpKLl1W0ac7luUWx-DTawzIP_dU8ljcWA&usqp=CAU"
profileSize={30}
/>
<Profile
name="๊ท๋ฒ"
uri="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRxZTogMJ6-sBn0-3YBTCsUGSWFjDX_LOpiw_wQ8hEQamKuG4QZeZqQXSWARGetJ9B0CL4&usqp=CAU"
profileSize={30}
/>
</View>
)
}
/*ํจ์ํ ์ปดํฌ๋ํธ๋ก ํํ */
const Profile = (props) => {
return(
<View style={{flexDirection: "row"}}>
<Image source={{
uri: props.uri
}}
style={{
width: props.profileSize,
height: props.profileSize,
}}
/>
<Text>{props.name}</Text>
</View>
)
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});
2. ์ค์ค๋ก ํด๋ณด๊ธฐ
import { setStatusBarBackgroundColor } from "expo-status-bar";
import react from "react";
import { Image, View, Text, StyleSheet } from "react-native";
const Header = (props) => {
return<Text>{props.title}</Text>
}
const MyProfile = () => {
return(
<Profile
name = "์๋ฏผ"
uri = "https://i.ytimg.com/vi/qDhOhTtPLng/maxresdefault.jpg"
fontSize = {40}
/>
)
}
const Division = () => {
return(
<Text>Division</Text>
)
}
const FriendSection = () => {
return(
<Text>FriendSection</Text>
)
}
const FriendList = () => {
return(
<View>
<Profile
name = "์งํ"
uri = "https://www.sisain.co.kr/news/photo/202110/45791_82634_4851.jpg"
fontSize = {40}
/>
<Profile
name = "๋ฏผํ"
uri = "https://cdn.healthinnews.co.kr/news/photo/202204/29034_29822_2928.jpg"
fontSize = {40}
/>
<Profile
name = "์๋ก"
uri = "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQqKqzXig2zL4ZUAvFgNqn1VG4vxsj3rUoIwvSCy_mATvLxYrbUHiXLSVCwAq_MRoSxAKg&usqp=CAU"
fontSize = {40}
/>
<Profile
name = "์ฌ์ฑ"
uri = "http://www.newsjinju.kr/news/photo/202101/16352_20174_1135.jpeg"
fontSize = {40}
/>
<Profile
name = "๊ท๋ฒ"
uri = "https://blog.kakaocdn.net/dn/c7dQje/btrAb9oL0Ke/WAad01aEfiHJdnyVaZBe4K/img.png"
fontSize = {40}
/>
</View>
)
}
const Profile = (props) => {
return(
<View style={{flexDirection: "row"}}>
<Image source={{
uri: props.uri
}}
style = {{
width: props.fontSize,
height: props.fontSize
}}
/>
<Text>{props.name}</Text>
</View>
)
}
export default function App() {
return (
<View style={styles.container}>
<Header title="์น๊ตฌ๋ชฉ๋ก"/>
<MyProfile/>
<Division/>
<FriendSection/>
<FriendList/>
</View>
)
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});
CSS ๊ฐ ์ ์ฉ์ด ์๋์๋๋ฐ, View์ ์์ฑ์ผ๋ก Style์ด ์๋ Styles๋ผ๊ณ ์ณ์ ๊ทธ๋ฌ๋ค. 30๋ถ ์ ๋ ์๋น ํ๋ค.