6.2.1 children Props

    children Props는 우리가 Text 컴포넌트에서 사용하는 것처럼 컴포넌트 태그 사이에 넣어준 값입니다. Box라는 컴포넌트를 임시적으로 FeedsScreen 내부에 만들어보겠습니다.

    screens/FeedsScreen.js

    import React from 'react';
    import {StyleSheet, View, Text} from 'react-native';
    import LogContext from '../contexts/LogContext';
    
    function FeedsScreen() {
      return (
        <View style={styles.block}>
          <Box>
            <Text>1</Text>
          </Box>
          <Box>
            <Text>2</Text>
          </Box>
          <Box>
            <Text>3</Text>
          </Box>
        </View>
      );
    }
    
    function Box({children}) {
      return <View style={styles.box}>{children}</View>;
    }
      const styles = StyleSheet.create({
        box: {
        borderWidth: 2,
        padding: 16,
        borderBottomColor: 'black',
        marginBottom: 16,
      },
    });
    
    export default FeedsScreen;
    신간 소식 구독하기
    뉴스레터에 가입하시고 이메일로 신간 소식을 받아 보세요.