프레젠테이션 컴포넌트란? 자식 컴포넌트에게 프롭스를 전달하는 역할만 하는 컴포넌트
프롭스 드릴링이란?
데이터(혹은 함수)를 상위 컴포넌트에서 하위 컴포넌트로 전달하기 위해, 중간 컴포넌트들을 거쳐야 하는 패턴
예시 코드
// App.js
function App() {
const user = "User1"; // 최상위에서 데이터 생성
return <ParentComponent user={user} />;
}
// ParentComponent.js
function ParentComponent({ user }) {
return <ChildComponent user={user} />;
}
// ChildComponent.js
function ChildComponent({ user }) {
return <GrandChildComponent user={user} />;
}
// GrandChildComponent.js
function GrandChildComponent({ user }) {
// 데이터가 최종적으로 렌더링되는 프레젠테이션 컴포넌트
return <div>{user}</div>;
}