Styled-components란?
리액트에서 CSS-in-JS 방식으로 컴포넌트를 꾸밀수 있게 도와주는 패키지
컴포넌트에 공통으로 적용할 스타일을 만든다
백틱(`)으로 감싸서 작성한다
const StBox = styled.div`
width: 100px;
height: 100px;
border: 1px solid ${(props) => props.borderColor};
margin: 20px;
`;
const boxList = ["red", "green", "blue"];
const getBoxName = (color) => {
switch (color) {
case "red":
return "빨간박스";
case "green":
return "초록박스";
case "blue":
return "파란박스";
default:
return "검정박스";
}
};
function App() {
return (
<>
{boxList.map(function (boxColor) {
return (
<StBox key={boxColor} borderColor={boxColor}>
{getBoxName(boxColor)}
</StBox>
);
})}
</>
);
}

'🩵 React > 학습 노트' 카테고리의 다른 글
[React🩵] useRef (0) | 2025.03.14 |
---|---|
[React🩵] useEffect와 components lifecycle (컴포넌트의 생명주기) (0) | 2025.03.14 |
[React🩵] useState (0) | 2025.02.28 |
[React🩵] Props (0) | 2025.02.27 |
[React🩵] id와 className (0) | 2025.02.27 |