Props Drilling 지우기 | Frontend Fundamentals #77
Replies: 4 comments 14 replies
-
안녕하세요. 저도 개발하다보면서 Props Drilling 에 대해서 꾸준한 고민이 있었습니다. 질문: Props Drilling 이 3단계 이상에 걸쳐서 진행된 경우 어떻게 Props Drilling 을 지울 것인지?
그런데 만약, 아래와 같이 동일한 Props를 계속해서 넘겨받는 Props Drilling 문제가 있다면 어떻게 관리할 것인지 궁금합니다.
감사합니다. |
Beta Was this translation helpful? Give feedback.
-
안녕하세요, 저는 위에서 이야기 나누어주신 방향과 약간은 다른 이야기이지만 문서를 이런 방향으로 더 디벨롭해보면 어떨까 하는 생각에 의견을 남겨봅니다! (이미 Context API 예시로 변경될 예정이기때문에 이 방향이 적용될 수 있을지는 모르겠네요 :) ) 저는 ItemEditModal -> ItemEditBody -> ItemEditList 를 ItemEditModal -> ItemEditList 로 변경하는 과정에서 강조된 액션 아이템은 조합을 통해 Drilling을 줄이는 방향을 제시해주었지만 itemEditBody 자체만으로 내부 구현을 감추고 복잡도를 낮춘다는 점도 추상화(컴포넌트화) 하는 것에는 의미가 있지만 위와 같은 경우에서는 Atomic한 Input, Button 컴포넌트는 충분히 그 자체 컴포넌트로도 재사용성의 관점에서 추상화되어있는 단위이기때문에 이들은 굳이 함께 감추지 않고 드러내면서 drilling을 최소화한다는 맥락을 함께 소개하면 이해에 도움을 줄 수 있겠다고 생각했어요. 이와 같이 추상화하는 과정에서 이를 컴포넌트화할 가치가 있는지를 판단하는 두가지 기준인
라는 기준과 조합의 미학을 함께 고민해본다면 문서에 작성해주신 조합을 통해 어느정도의 구현을 드러내는 것이 조금은 더 합리적인 결과물이라고 생각하게 될 것으로 보여 이러한 맥락을 함께 소개하면 코드 냄새를 맡고 개선하고자 할 때 판단에 있어 |
Beta Was this translation helpful? Give feedback.
-
이 글만 보아도 대체로 가독성 보다는 예측 가능성을 더 높은 우선순위로 보는 것 같다는 생각이 드네요! |
Beta Was this translation helpful? Give feedback.
-
props drilling에 대한 전체적인 의견에 대해서는 공감하지만, 글의 예시는 컴포넌트 구조가 잘못됐다고 느껴져요.
이런 구조 때문에 컴포넌트 depth가 깊어져서 props drilling도 일어나게 된 것 같고 전반적인 맥락 이해가 어려워졌다고 생각해요. 저는 해당 컴포넌트를 해체해서 아래와 같이 코드를 작성할 것 같아요. function ItemEditModal({ open, items, recommendedItems, onConfirm, onClose }) {
const [keyword, setKeyword] = useState("");
// 다른 ItemEditModal 로직 ...
return (
<Modal open={open} onClose={onClose}>
<ItemEditSearch
keyword={keyword}
onKeywordChange={setKeyword}
onClose={onClose}
/>
<ItemEditList
keyword={keyword}
items={items}
recommendedItems={recommendedItems}
onConfirm={onConfirm}
/>
{/* ... 다른 ItemEditModal 컴포넌트 ... */}
</Modal>
);
}
function ItemEditSearch({
keyword,
onKeywordChange,
onClose,
}) {
return (
<div style={{ display: "flex", justifyContent: "space-between" }}>
<Input
value={keyword}
onChange={(e) => onKeywordChange(e.target.value)}
/>
<Button onClick={onClose}>닫기</Button>
</div>
);
}
function ItemEditList({
keyword,
items,
recommendedItems,
onConfirm,
}) {
// ...
}
이렇게 하면 컴포넌트 depth가 줄어들고 props drilling도 줄어들어서 코드 이해도가 높아질 것 같아요. |
Beta Was this translation helpful? Give feedback.
-
Props Drilling 지우기 | Frontend Fundamentals
변경하기 쉬운 프론트엔드 코드를 위한 지침서
https://frontend-fundamentals.com/code/examples/item-edit-modal.html
Beta Was this translation helpful? Give feedback.
All reactions