리액트 네이티브에서 style 을 조건에 따라 적용하는 법 (How to apply style with conditional in React Native)



## 리액트 네이티브에서 style 을 조건에 따라 적용하는 법 (How to apply style with conditional in React Native)

최근 리액트 네이티브 프로젝트에 참가하게 됐다. JavaScript 를 자주 쓰진 않아 상당히 어색하지만, 빠르게 적응하려고 노력 중이다.

작업 중 React Native에서 Style을 조건에 따라서 적용해야 하는 상황이 있었는데 다음과 같이 처리할 수 있다.

```
return (
  <View style={ someCondition ? styles.yellowContainer : styles.greenContainer }>
    <Text>Great!</Text>
  </View>
)

const styles = StyleSheet.create({
 yellowContainer: {
  backgroundColor: '#fff000'
 },
 greenContainer: {
  backgroundColor: '#08d13b'
 },
})
```



댓글

이 블로그의 인기 게시물

부트스트랩 사용 시 버튼 오른쪽 정렬하는 방법 (How to use float-right for right align in bootstrap)

맥(Mac)에서 MySql 사용 시 Error: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) 오류가 발생하는 경우 해결 방법

HTML, CSS - footer fixed (foot 하단 고정 시키기)