React_children

지원·2024년 3월 3일

React

목록 보기
71/71
post-thumbnail

children

리액트에서의 "children"은 컴포넌트의 내용을 나타내는 특별한 프로퍼티

function ParentComponent() {
  return (
    <div>
      <h1>Parent Component</h1>
      <ChildComponent />
    </div>
  );
}
function ChildComponent() {
  return <p>This is a Child Component</p>;
}

ParentComponent는 ChildComponent를 포함하고 있다. ChildComponent를 ParentComponent의 자식으로써 렌더링하고 있다.

ChildComponent가 ParentComponent의 children

ParentComponent의 children은
This is a Child Component가 된다.

이러한 구조는 중첩된 컴포넌트에서 유용하게 사용돤다.

children 프로퍼티를 사용하여 부모 컴포넌트가
자식 컴포넌트에게 데이터나 동작을 전달할 수 있다.
또한 컴포넌트의 구조를 유연하게 만들어 재사용성을 높이는 데 도움이 된다.

0개의 댓글