코딩공부/React

Styled-components 변수처리&확장

hyunee_p 2022. 3. 29. 02:32
import React from 'react';
import styled from 'styled-components';

const Father = styled.div`
  display: flex;
`;

const Box = styled.div`
  background-color: ${(props) => props.bgColor};
  width: 100px;
  height: 100px;
`;

// 확장
// Box의 속성을 들고온 다음 새로운 속성을 추가해준다.
const Circle = styled(Box)`
  border-radius: 50px;
`;

function App() {
  return (
    <Father>
      <Box bgColor="teal"/>
      <Circle bgColor="tomato"/>
    </Father>
  );
}

export default App;