f8b21af4be
10_Wiki/Topics 대규모 정리: - 오류 캡처/미완성 stub 문서 227개 제거 - 교차폴더 중복 43클러스터 병합 (63파일 → redirect) - 링크명 정규화: 깨진 링크 수정·redirect 직결·개념 매핑 ~2,400건 - 카테고리 MOC 6개 신규 생성 - Graph 섹션 미해결 related-keyword 링크 10,058건 제거 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
5.9 KiB
5.9 KiB
id, title, category, status, canonical_id, aliases, duplicate_of, source_trust_level, confidence_score, verification_status, tags, raw_sources, last_reinforced, github_commit, tech_stack
| id | title | category | status | canonical_id | aliases | duplicate_of | source_trust_level | confidence_score | verification_status | tags | raw_sources | last_reinforced | github_commit | tech_stack | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| wiki-2026-0508-프론트엔드-컴포넌트-구조화 | 프론트엔드 컴포넌트 구조화 | 10_Wiki/Topics | verified | self |
|
none | A | 0.9 | applied |
|
2026-05-10 | pending |
|
프론트엔드 컴포넌트 구조화
매 한 줄
"매 component 의 size, scope, composition 의 systematic decomposition". 매 atomic design (atom→molecule→organism), feature-based (colocation), compound component, headless UI 의 4-axis. 매 2026 의 default — feature-folder + headless primitives (Radix/Ark) + Server Components.
매 핵심
매 4 가지 axis
- Size: atom · molecule · organism · template · page (Atomic Design).
- Scope: feature-local vs shared / design system.
- Composition: leaf vs container vs compound vs headless.
- Boundary: Server Component vs Client Component (RSC).
매 file/folder strategy
- Co-location:
components/Button/{index.tsx, Button.css, Button.test.tsx, Button.stories.tsx}. - Feature folder:
features/checkout/{components, hooks, api, types}— feature 의 self-contained. - Shared design system:
packages/ui— monorepo + workspace.
매 응용
- Component library / design system 구축.
- Large app 의 modular feature decomposition.
- Server Components 의 server/client boundary 결정.
💻 패턴
1. Atomic Design folder
src/components/
atoms/ Button, Input, Icon
molecules/ SearchBar, FormField
organisms/ Header, ProductCard
templates/ CheckoutLayout
2. Feature-based folder (recommended 2026)
src/features/checkout/
components/CheckoutForm.tsx
hooks/useCheckout.ts
api/createOrder.ts
schemas/order.ts
index.ts // public API
3. Compound component
function Tabs({ children, defaultValue }: Props) {
const [value, setValue] = useState(defaultValue);
return <TabsContext.Provider value={{ value, setValue }}>{children}</TabsContext.Provider>;
}
Tabs.List = TabsList;
Tabs.Trigger = TabsTrigger;
Tabs.Content = TabsContent;
// Usage:
<Tabs defaultValue="a">
<Tabs.List><Tabs.Trigger value="a">A</Tabs.Trigger></Tabs.List>
<Tabs.Content value="a">...</Tabs.Content>
</Tabs>
4. Headless component (Radix-style)
function useDisclosure() {
const [open, setOpen] = useState(false);
return { open, toggle: () => setOpen(o => !o), close: () => setOpen(false) };
}
// Consumer styles freely
function MyDialog() {
const d = useDisclosure();
return <div className="my-styles">{d.open && '...'}</div>;
}
5. Server / Client boundary (Next.js 15)
// app/products/page.tsx (Server Component — default)
import { ProductList } from './ProductList';
import { db } from '@/db';
export default async function Page() {
const products = await db.product.findMany();
return <ProductList products={products} />;
}
// app/products/AddToCart.tsx
'use client';
export function AddToCart({ id }: { id: string }) {
return <button onClick={() => addToCart(id)}>Add</button>;
}
6. Polymorphic component (as prop)
type BoxProps<T extends React.ElementType> = {
as?: T;
} & React.ComponentPropsWithoutRef<T>;
function Box<T extends React.ElementType = 'div'>({ as, ...rest }: BoxProps<T>) {
const Tag = as || 'div';
return <Tag {...rest} />;
}
<Box as="a" href="/x">link</Box>;
7. Container / Presentational split (when useful)
// Container — data + logic
function UserListContainer() {
const { data } = useUsers();
return <UserListView users={data} />;
}
// Presentational — pure UI
function UserListView({ users }: { users: User[] }) {
return <ul>{users.map(u => <li key={u.id}>{u.name}</li>)}</ul>;
}
8. Public API barrel (index.ts)
// features/checkout/index.ts
export { CheckoutForm } from './components/CheckoutForm';
export { useCheckout } from './hooks/useCheckout';
export type { Order } from './schemas/order';
// 매 internal 은 export X — encapsulation.
매 결정 기준
| 상황 | Approach |
|---|---|
| Design system | Atomic + headless (Radix/Ark) |
| Product feature | Feature folder + co-location |
| Multi-trigger UI (Tabs, Menu) | Compound component |
| Style flexibility | Headless + custom CSS |
| Next.js 15 app | Server-default, Client only when needed |
| Reusable variant via tag | Polymorphic as |
기본값: 매 feature folder + 매 headless primitives (Radix/Ark) + 매 Server Components default.
🔗 Graph
- 부모: Component-Composition · Large_Frontend_Projects
- 변형: Atomic Design · Component-Composition · Headless UI · Modern_Web_Rendering_and_Optimization
- 응용: Design System · Monorepo
- Adjacent: Custom Hooks · Render_Props
🤖 LLM 활용
언제: 매 large app 의 component decomposition 결정 시. 매 server/client boundary planning 시. 언제 X: 매 prototype / single-page demo — 매 over-structuring 의 X.
❌ 안티패턴
- God component: 매 1000-line component — 매 split.
- Atomic Design 의 dogmatic 적용: 매 feature 에는 feature folder 가 더 적합.
- 'use client' 남발: 매 root 에 client 선언 — 매 RSC benefit 상실.
- Container/Presentational 강요: 매 hooks 시대에는 obsolete pattern.
- Barrel re-export 의 deep nesting: 매 bundler tree-shaking 방해.
🧪 검증 / 중복
- Verified (React docs, Next.js 15 docs, Radix UI / Ark UI patterns).
- 신뢰도 A.
🕓 Changelog
| 날짜 | 변경 |
|---|---|
| 2026-05-08 | Phase 1 |
| 2026-05-10 | Manual cleanup — 4-axis decomposition + 8 patterns + RSC boundary |