Styled Components : scss 코드를 설치 없이 사용하고 css 파일 없이 사용,
컴포넌트에 스타일을 적용하여 스타일 코드를 몰아 넣을 수 있으며 공통 코드를 줄이고 React의 컴포넌트 형태로 사용할 수 있다.
css in js 기술 - js안에서 css를 사용할 수 있는 것
npm i styled-components
App.js에 import './App.css'를 제거하고 아래 구문 추가
import styled from 'styled-components';
sass 작업 없이 스타일을 적용할 수 있다.
styled.태그이름 을 사용해서 바로 react component를 만들 수 있다.
import React from 'react'; import styled from 'styled-components';
function App() {
return (
<Container>
<Button />
<Button danger />
</Container>
);
}
const Container = styled.div`
width: 100%;
height: 100vh;
background-color: #bdc3c7;
`;
const Button = styled.button`
border-radius: 50px;
padding: 5px;
min-width: 120px;
color: white;
font-weight: 600;
-webkit-appearance: none;
cursor: pointer;
&:active,
&:foucus {
outline: none;
}
`;
export default App;
최대 장점
- 템플릿 리터럴을 사용한다.
- prop을 이용해 css 옵션을 조정할 수 있고, 여러 css를 조절할 수도 있다.
글로벌 사용
https://www.howdy-mj.me/css/styled-components-with-global-style/
Styled Components를 Global에서 사용하기(w/반응형)
해당 글은 React를 기준으로 작성되었습니다. Styled Components란? Styled Components는 CSS-in-JS의 하나로, CSS를 하나의 컴포넌트로 만들어 주는 것이다. Styled Components 설치 Button 자체가 하나의 Component가 되
www.howdy-mj.me
출처
[Styling] Styled Components 이해하고 사용하기! (with React) 💅
Styled Components 1. 스타일? Styled Components를 왜 배우는가! SASS 코드를 설치 없이 사용하고 CSS 파일 없이 CSS 코드를 짜고 게다가 이 코드를 React Native 앱으로 공유할수 있습니다. 가장 큰 장점은 기..
xtring-dev.tistory.com
'Development > React.js' 카테고리의 다른 글
[React] router 이동시, 에러 (0) | 2022.02.04 |
---|---|
[React] 리엑트 컴포넌트 - 함수형 (0) | 2022.01.26 |
[React] 웹팩을 활용한 리엑트 개발 환경 셋팅 (0) | 2022.01.24 |
[React] 리엑트 CSS 사용하기 (0) | 2022.01.23 |
[React] npm vs npx (0) | 2022.01.21 |