refactor(topics): 멀티 에이전트용 지식 재편 — _Common(공통 기본기) + Domain_* 구조
에이전트 8종(대화형/프로그래머 C·S/디자이너/설계자/기획자/QA/PD/PM)에게 [공통 기본 능력 + 롤별 Specialty] 2층으로 지식을 주입하기 위한 재분류. 문서 내용·포맷은 무수정, 폴더 이동만 (6,372개 문서 수 보존 확인). - Topic_Programming → Domain_Programming (내부 구조 보존) - Topic_Graphic → Domain_Design - Topic_Business → Domain_Product - Topic_General → Domain_General - _Common 신설: Math(구 Topic_Math_Specialty), Reasoning(구 General/From_Thinking & Reasoning), Reasoning_Creativity(구 General/From_창의성), Communication(Poetic_Blog_Writing + From_writing) - 타 도메인의 From_* 폴더는 유지 (출처 표기일 뿐, 이미 도메인에 맞게 분류된 문서) - 빈 폴더 정리 (memory/procedures) - 에이전트→폴더 매핑은 workspace의 .astra/agent-knowledge-map.json (9개 에이전트) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
---
|
||||
id: react-component-composition
|
||||
title: 컴포넌트 합성 (Composition over Configuration)
|
||||
category: Coding
|
||||
status: draft
|
||||
source_trust_level: B
|
||||
verification_status: conceptual
|
||||
created_at: 2026-05-09
|
||||
updated_at: 2026-05-09
|
||||
tags: [react, composition, children, slots, vibe-coding]
|
||||
tech_stack: { language: "TypeScript / React 18+", applicable_to: ["Web", "React Native"] }
|
||||
applied_in: []
|
||||
aliases: [render props, compound components, slot pattern]
|
||||
---
|
||||
|
||||
# 컴포넌트 합성 (Composition)
|
||||
|
||||
> 새 옵션 props 추가가 답답해지면 멈춰라. **자식이 직접 채우게 하는 합성**이 prop 폭발보다 거의 항상 낫다. boolean prop 30개 컴포넌트는 anti-signal.
|
||||
|
||||
## 📖 핵심 개념
|
||||
3가지 합성 패턴:
|
||||
1. **Children pass-through**: `{children}` 받아 가운데에 끼움
|
||||
2. **Slot props (named children)**: `header` / `footer` 등 이름 있는 영역
|
||||
3. **Compound components**: `<Tabs><Tab/><Tab/></Tabs>` 같이 부모 + 자식 협력
|
||||
|
||||
## 💻 코드 패턴
|
||||
|
||||
### Children pass-through
|
||||
```tsx
|
||||
function Card({ children }: { children: ReactNode }) {
|
||||
return <div className="card-shell">{children}</div>;
|
||||
}
|
||||
<Card><h2>Title</h2><p>body</p></Card>
|
||||
```
|
||||
|
||||
### Slot props
|
||||
```tsx
|
||||
function Modal({ title, body, actions }: { title: ReactNode; body: ReactNode; actions: ReactNode }) {
|
||||
return <div className="modal">
|
||||
<header>{title}</header>
|
||||
<section>{body}</section>
|
||||
<footer>{actions}</footer>
|
||||
</div>;
|
||||
}
|
||||
<Modal title="삭제" body="정말?" actions={<><button>취소</button><button>삭제</button></>} />
|
||||
```
|
||||
|
||||
### Compound components
|
||||
```tsx
|
||||
const TabsContext = createContext<{ active: string; setActive: (k: string) => void } | null>(null);
|
||||
|
||||
function Tabs({ defaultActive, children }: ...) {
|
||||
const [active, setActive] = useState(defaultActive);
|
||||
return <TabsContext.Provider value={{ active, setActive }}>{children}</TabsContext.Provider>;
|
||||
}
|
||||
function TabList({ children }) { return <div role="tablist">{children}</div>; }
|
||||
function Tab({ id, children }: { id: string; children: ReactNode }) {
|
||||
const ctx = useContext(TabsContext)!;
|
||||
return <button onClick={() => ctx.setActive(id)} aria-selected={ctx.active === id}>{children}</button>;
|
||||
}
|
||||
function TabPanel({ id, children }) {
|
||||
const ctx = useContext(TabsContext)!;
|
||||
return ctx.active === id ? <div>{children}</div> : null;
|
||||
}
|
||||
|
||||
Tabs.List = TabList; Tabs.Tab = Tab; Tabs.Panel = TabPanel;
|
||||
|
||||
<Tabs defaultActive="a">
|
||||
<Tabs.List><Tabs.Tab id="a">A</Tabs.Tab><Tabs.Tab id="b">B</Tabs.Tab></Tabs.List>
|
||||
<Tabs.Panel id="a">…</Tabs.Panel><Tabs.Panel id="b">…</Tabs.Panel>
|
||||
</Tabs>
|
||||
```
|
||||
|
||||
## 🤔 의사결정 기준
|
||||
| 상황 | 패턴 |
|
||||
|---|---|
|
||||
| 단순 wrapper (border, padding) | children |
|
||||
| 정해진 레이아웃, 영역 의미 다름 | slot props |
|
||||
| 부모-자식 상태 공유 (Tabs, Accordion, Menu) | compound components |
|
||||
| 외부에서 마음대로 조립 가능해야 | render props 또는 hook 노출 |
|
||||
| 옵션이 5개 이상의 boolean prop | composition 으로 리팩터 |
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **boolean prop 폭발**: `<Button primary danger small loading rounded outlined ... />`. variant prop 도입 또는 합성.
|
||||
- **자식 종류 검사 후 강제** (`children.type === Tab`): 깨지기 쉬움. Context 기반 통신.
|
||||
- **render props 남발**: hook 으로 충분한데 함수 prop 일렬. hook 권장.
|
||||
- **slot 인데 ReactNode 가 아닌 string 받기**: 유연성 손실. 보통 ReactNode.
|
||||
- **Compound 인데 Context 없이 구현**: prop drilling 또는 imperative 검사.
|
||||
|
||||
## 🤖 LLM 활용 힌트
|
||||
- "이 컴포넌트의 prop 가 5개 이상 boolean 이면 합성으로" 강조.
|
||||
- compound 패턴은 ARIA 속성도 같이 챙겨야 — accessibility 검토 명시.
|
||||
|
||||
## 🔗 관련 문서
|
||||
- [[React_Custom_Hook_Patterns]]
|
||||
- [[React_Refs_Patterns]]
|
||||
Reference in New Issue
Block a user