Program/React Native

Styled Components

하랑파파♡ 2020. 2. 6. 14:08
728x90
반응형
SMALL

#Styled components

- react-native에서 스타일을 적용하는 방법

-> 인라인 방식
-> StyleSheet
-> Styled Components

- Styled Components를 사용하는 이유

-> react와 react-native에 동일한 스타일 코드를 적용
-> reac-native에서 스타일은 오브젝트 형식으로 사용
  => text-align => textAlugn
-> 동적으로 변경하는 스타일을 관리하기 쉽다
  => props를 사용할 수 있다
-> 배포시 파일용량이 커진다

- Styled Components 설치

npm install --save styled-components
npm install --save-dev @types/styled-components
    -> styled-components : Styled Components 라이브러리
    -> @types/styled-components : typescript를 위한 Styled Components의 타입 정의 파일

- Styled Components를 react-native에 추가

import Styled from 'styled-components/native';
    -> 'styled-components/native'의 대소문자 주의
    -> react-native에서는 'styled-components/native' 를 쓴다
728x90
반응형
LIST

'Program > React Native' 카테고리의 다른 글

React Native 프로젝트 설정 : typescript  (0) 2020.03.05
Props와 State  (0) 2020.02.08
절대경로로 컴포넌트 추가  (0) 2020.02.06
React Native Typescript  (0) 2020.02.06
Mac에서 React Native 개발환경 만들기  (0) 2020.02.06