Open WONILLISM opened 2 years ago
컴포넌트를 확장함에 있어서 상속을 받는 방법도 있다.
import styled from 'styled-components';
const Father = styled.div`
display: flex;
`;
const Box = styled.div`
background-color: ${props => props.bgColor};
width: 100px;
height: 100px;
`;
const Circle = styled(Box)`
border-radius: 50px;
`;
function App() {
return (
<Father>
<Box bgColor="teal" />
<Circle bgColor="tomato" />
</Father>
);
}
export default App;
같은 기능을하는 컴포넌트를 중복해서 쓰고싶지 않을 때는 props를 이용하면 된다.