본문 바로가기

STUDY/Front

React-native #1) Props란?

리액트는 다수의 컴포넌트로 이루어져있는 결정체.

컴포넌트 간 값을 공유하기 위해서 Props 객체를 사용한다.

 

Props란?

클라이언트 베이스로 컴포넌트 간 데이터 공유를 위해 사용되는 객체

 

예제 

<View style = {styles.container}>
        <Text style = {styles.hello}>SPONGE 화이팅하자구</Text>
        <JUDY type = 'one'/>
        <JUDY type = 'two'/>
</View>
class JUDY extends Component{


    render (){
        let judyImg = '';
        if(this.props.type === 'one'){
            judyImg = require('./assets/image.png');
        }else if(this.props.type === 'two'){
            judyImg = require('./assets/judy2.jpg');
        }
        return (
            <View>
                <Image source = {judyImg} style={{width: 100, height:100}}/>
            </View>
        )
    }
}

반응형