카테고리 없음

margin 대신 HeightBox

stella0905 2023. 4. 27. 12:15
import React from "react";
import styled from "styled-components";

function HeightBox({ height }) {
  return <StyledDiv height={height} />;
}

export default HeightBox;

const StyledDiv = styled.div`
  height: ${(props) => props.height}px;
`;

<HeightBox height={10} />는 특정 높이의 공간을 만들기 위한 스타일드 컴포넌트이다다. 이 공간은 margin 속성으로 만들 수도 있지만, margin은 주변 요소들에도 영향을 미칠 수 있기 때문에 컴포넌트 간에 간격을 일정하게 유지하기 위해 사용한다.

또한, margin을 사용하면 컴포넌트의 구조와 무관하게 일정한 간격을 유지하기 어렵기 때문에, <HeightBox height={10} />와 같은 스타일드 컴포넌트를 사용하는 것이 일반적이다다. 따라서, <HeightBox height={10} />를 사용하는 것은 일반적인 React 개발에서도 자주 사용되는 방법 중 하나이다다.