테이블(Table) v2 → v3 마이그레이션
HeroUI v2의 Table을 v3로 옮길 때 필요한 변경을 정리한 가이드예요. v3에서는 각 부분이 분리된 named import 대신 점 표기법(dot notation)의 합성 컴포넌트 패턴을 사용하고, Table.ScrollContainer와 Table.Content라는 새 래퍼 컴포넌트가 추가되었어요. 구조, props 이동, 선택, 페이징 등이 어떻게 달라지는지 차근차근 살펴볼게요.
출처: HeroUI
본문
참고: 완전한 API 레퍼런스, 스타일링 가이드, 고급 예제는 v3 Table 문서를 참고하세요. 이 가이드는 HeroUI v2에서 마이그레이션하는 부분에만 집중합니다.
구조 변화
v2에서는 Table이 각 부분에 대해 분리된 named import를 사용했어요:
import { Table, TableHeader, TableColumn, TableBody, TableRow, TableCell } from "@heroui/react";
export default function App() {
return (
<Table aria-label="Example table">
<TableHeader>
<TableColumn>Name</TableColumn>
<TableColumn>Role</TableColumn>
</TableHeader>
<TableBody>
<TableRow key="1">
<TableCell>Kate Moore</TableCell>
<TableCell>CEO</TableCell>
</TableRow>
</TableBody>
</Table>
);
}
v3에서는 Table이 점 표기법의 합성 컴포넌트 패턴을 사용하고 Table.ScrollContainer와 Table.Content를 추가해요:
import { Table } from "@heroui/react";
export default function App() {
return (
<Table>
<Table.ScrollContainer>
<Table.Content aria-label="Example table">
<Table.Header>
<Table.Column>Name</Table.Column>
<Table.Column>Role</Table.Column>
</Table.Header>
<Table.Body>
<Table.Row>
<Table.Cell>Kate Moore</Table.Cell>
<Table.Cell>CEO</Table.Cell>
</Table.Row>
</Table.Body>
</Table.Content>
</Table.ScrollContainer>
</Table>
);
}
주요 변경 사항
1. 컴포넌트 구조
v2: 분리된 named imports (Table, TableHeader, TableColumn, TableBody, TableRow, TableCell)
v3: 점 표기법의 단일 import: Table, Table.ScrollContainer, Table.Content, Table.Header, Table.Column, Table.Body, Table.Row, Table.Cell, Table.Footer
2. 새 래퍼 컴포넌트
Table이제 루트 컨테이너(스타일링 래퍼)Table.ScrollContainer커스텀 스크롤바로 가로 스크롤 처리Table.Content실제<table>요소 (aria-label,selectionMode,sortDescriptor등이 여기 감)Table.Footer페이징 및 기타 푸터 콘텐츠를 위한bottomContent대체
3. Prop 변경
| v2 Prop | v3 Equivalent | Notes |
|---|---|---|
aria-label |
Table.Content aria-label |
Moved to Table.Content |
selectionMode |
Table.Content selectionMode |
Moved to Table.Content |
selectedKeys |
Table.Content selectedKeys |
Moved to Table.Content |
defaultSelectedKeys |
Table.Content defaultSelectedKeys |
Moved to Table.Content |
onSelectionChange |
Table.Content onSelectionChange |
Moved to Table.Content |
sortDescriptor |
Table.Content sortDescriptor |
Moved to Table.Content |
onSortChange |
Table.Content onSortChange |
Moved to Table.Content |
disabledKeys |
Table.Content disabledKeys |
Moved to Table.Content |
disallowEmptySelection |
Table.Content disallowEmptySelection |
Moved to Table.Content |
selectionBehavior |
Table.Content selectionBehavior |
Moved to Table.Content |
disabledBehavior |
Table.Content disabledBehavior |
Moved to Table.Content |
onRowAction |
Table.Content onRowAction |
Moved to Table.Content |
onCellAction |
Table.Content onCellAction |
Moved to Table.Content |
topContent |
- | Place content inside Table before Table.ScrollContainer |
bottomContent |
- | Use Table.Footer |
topContentPlacement |
- | Removed (compose layout directly) |
bottomContentPlacement |
- | Removed (compose layout directly) |
color |
- | Removed (use Tailwind CSS) |
variant |
Table variant |
Changed to "primary" (card-style, default) or "secondary" (flat) |
layout |
- | Removed |
radius |
- | Removed (use Tailwind CSS) |
shadow |
- | Removed (use Tailwind CSS) |
isStriped |
- | Removed (use Tailwind CSS) |
isCompact |
- | Removed (use Tailwind CSS) |
isHeaderSticky |
- | Removed (use Tailwind CSS sticky top-0) |
fullWidth |
- | Removed (full width by default) |
removeWrapper |
- | Removed (compose layout directly) |
hideHeader |
- | Removed (omit Table.Header or use CSS) |
isVirtualized |
- | Use React Aria Virtualizer wrapper |
maxTableHeight |
- | Use CSS or Virtualizer |
rowHeight |
- | Use TableLayout with Virtualizer |
isKeyboardNavigationDisabled |
- | Removed |
disableAnimation |
- | Removed |
classNames |
- | Use className on individual compound components |
4. 체크박스로 선택
v2: selectionMode가 설정되면 테이블이 체크박스를 자동 렌더링
v3: 열과 행에 slot="selection"이 있는 Checkbox를 명시적으로 사용
5. 로딩 및 빈 상태
v2: TableBody의 loadingState, loadingContent, emptyContent props
v3: Table.Body의 renderEmptyState prop; 무한 스크롤 로딩에는 Table.LoadMore 사용
6. 페이징
v2: Table의 bottomContent prop
v3: Table.Footer 합성 컴포넌트
7. 열 크기 조정(Column Resizing)
v2: 내장 아님
v3: Table.ResizableContainer + Table.ColumnResizer 합성 컴포넌트
마이그레이션 예제
기본 테이블
v2:
import { Table, TableHeader, TableColumn, TableBody, TableRow, TableCell } from "@heroui/react";
<Table aria-label="Users">
<TableHeader>
<TableColumn>Name</TableColumn>
<TableColumn>Role</TableColumn>
<TableColumn>Status</TableColumn>
</TableHeader>
<TableBody>
<TableRow key="1">
<TableCell>Kate Moore</TableCell>
<TableCell>CEO</TableCell>
<TableCell>Active</TableCell>
</TableRow>
<TableRow key="2">
<TableCell>John Doe</TableCell>
<TableCell>Developer</TableCell>
<TableCell>Active</TableCell>
</TableRow>
</TableBody>
</Table>
v3:
import { Table } from "@heroui/react";
<Table>
<Table.ScrollContainer>
<Table.Content aria-label="Users">
<Table.Header>
<Table.Column>Name</Table.Column>
<Table.Column>Role</Table.Column>
<Table.Column>Status</Table.Column>
</Table.Header>
<Table.Body>
<Table.Row id="1">
<Table.Cell>Kate Moore</Table.Cell>
<Table.Cell>CEO</Table.Cell>
<Table.Cell>Active</Table.Cell>
</Table.Row>
<Table.Row id="2">
<Table.Cell>John Doe</Table.Cell>
<Table.Cell>Developer</Table.Cell>
<Table.Cell>Active</Table.Cell>
</Table.Row>
</Table.Body>
</Table.Content>
</Table.ScrollContainer>
</Table>
동적 행(Dynamic Rows)
v2:
const columns = [
{ key: "name", label: "Name" },
{ key: "role", label: "Role" },
];
const rows = [
{ key: "1", name: "Kate", role: "CEO" },
{ key: "2", name: "John", role: "Developer" },
];
<Table aria-label="Users">
<TableHeader columns={columns}>
{(column) => <TableColumn key={column.key}>{column.label}</TableColumn>}
</TableHeader>
<TableBody items={rows}>
{(item) => (
<TableRow key={item.key}>
{(columnKey) => <TableCell>{item[columnKey]}</TableCell>}
</TableRow>
)}
</TableBody>
</Table>
v3:
const columns = [
{ id: "name", label: "Name" },
{ id: "role", label: "Role" },
];
const rows = [
{ id: "1", name: "Kate", role: "CEO" },
{ id: "2", name: "John", role: "Developer" },
];
<Table>
<Table.ScrollContainer>
<Table.Content aria-label="Users">
<Table.Header columns={columns}>
{(column) => <Table.Column id={column.id}>{column.label}</Table.Column>}
</Table.Header>
<Table.Body items={rows}>
{(item) => (
<Table.Row id={item.id}>
<Table.Cell>{item.name}</Table.Cell>
<Table.Cell>{item.role}</Table.Cell>
</Table.Row>
)}
</Table.Body>
</Table.Content>
</Table.ScrollContainer>
</Table>
선택(Selection)
v2:
const [selectedKeys, setSelectedKeys] = useState(new Set(["1"]));
<Table
aria-label="Users"
selectionMode="multiple"
selectedKeys={selectedKeys}
onSelectionChange={setSelectedKeys}
>
<TableHeader>
<TableColumn>Name</TableColumn>
<TableColumn>Role</TableColumn>
</TableHeader>
<TableBody>
<TableRow key="1">
<TableCell>Kate</TableCell>
<TableCell>CEO</TableCell>
</TableRow>
<TableRow key="2">
<TableCell>John</TableCell>
<TableCell>Developer</TableCell>
</TableRow>
</TableBody>
</Table>
v3:
import { Table, Checkbox } from "@heroui/react";
const [selectedKeys, setSelectedKeys] = useState(new Set(["1"]));
<Table>
<Table.ScrollContainer>
<Table.Content
aria-label="Users"
selectionMode="multiple"
selectedKeys={selectedKeys}
onSelectionChange={setSelectedKeys}
>
<Table.Header>
<Table.Column>
<Checkbox slot="selection" />
</Table.Column>
<Table.Column>Name</Table.Column>
<Table.Column>Role</Table.Column>
</Table.Header>
<Table.Body>
<Table.Row id="1">
<Table.Cell>
<Checkbox slot="selection" />
</Table.Cell>
<Table.Cell>Kate</Table.Cell>
<Table.Cell>CEO</Table.Cell>
</Table.Row>
<Table.Row id="2">
<Table.Cell>
<Checkbox slot="selection" />
</Table.Cell>
<Table.Cell>John</Table.Cell>
<Table.Cell>Developer</Table.Cell>
</Table.Row>
</Table.Body>
</Table.Content>
</Table.ScrollContainer>
</Table>
정렬(Sorting)
v2:
const [sortDescriptor, setSortDescriptor] = useState({
column: "name",
direction: "ascending",
});
<Table
aria-label="Users"
sortDescriptor={sortDescriptor}
onSortChange={setSortDescriptor}
>
<TableHeader>
<TableColumn key="name" allowsSorting>Name</TableColumn>
<TableColumn key="role" allowsSorting>Role</TableColumn>
</TableHeader>
<TableBody items={sortedItems}>
{(item) => (
<TableRow key={item.key}>
{(columnKey) => <TableCell>{item[columnKey]}</TableCell>}
</TableRow>
)}
</TableBody>
</Table>
v3:
const [sortDescriptor, setSortDescriptor] = useState({
column: "name",
direction: "ascending",
});
<Table>
<Table.ScrollContainer>
<Table.Content
aria-label="Users"
sortDescriptor={sortDescriptor}
onSortChange={setSortDescriptor}
>
<Table.Header>
<Table.Column id="name" allowsSorting>Name</Table.Column>
<Table.Column id="role" allowsSorting>Role</Table.Column>
</Table.Header>
<Table.Body items={sortedItems}>
{(item) => (
<Table.Row id={item.id}>
<Table.Cell>{item.name}</Table.Cell>
<Table.Cell>{item.role}</Table.Cell>
</Table.Row>
)}
</Table.Body>
</Table.Content>
</Table.ScrollContainer>
</Table>
페이징과 함께 (하단 콘텐츠)
v2:
<Table
aria-label="Users"
bottomContent={
<Pagination total={10} page={page} onChange={setPage} />
}
bottomContentPlacement="outside"
>
{/* ... */}
</Table>
v3:
<Table>
<Table.ScrollContainer>
<Table.Content aria-label="Users">
{/* Header and Body */}
</Table.Content>
</Table.ScrollContainer>
<Table.Footer>
{/* Pagination component */}
</Table.Footer>
</Table>
빈 상태(Empty State)
v2:
<TableBody emptyContent="No rows to display.">
{[]}
</TableBody>
v3:
<Table.Body
items={[]}
renderEmptyState={() => (
<p className="text-center py-4">No rows to display.</p>
)}
>
{[]}
</Table.Body>
스타일링 변경
v2: classNames Prop
<Table
classNames={{
base: "custom-base",
wrapper: "custom-wrapper",
table: "custom-table",
thead: "custom-header",
tbody: "custom-body",
tr: "custom-row",
th: "custom-column",
td: "custom-cell",
}}
/>
v3: 직접 className Props 사용
<Table className="custom-base">
<Table.ScrollContainer className="custom-wrapper">
<Table.Content aria-label="Table" className="custom-table">
<Table.Header className="custom-header">
<Table.Column className="custom-column">Name</Table.Column>
</Table.Header>
<Table.Body className="custom-body">
<Table.Row className="custom-row">
<Table.Cell className="custom-cell">Value</Table.Cell>
</Table.Row>
</Table.Body>
</Table.Content>
</Table.ScrollContainer>
</Table>
컴포넌트 구조(Anatomy)
v3 Table은 다음과 같은 구조를 가져요:
Table (Root container)
├── Table.ScrollContainer (horizontal scroll)
│ └── Table.Content (<table> element, aria-label, selectionMode, etc.)
│ ├── Table.Header (<thead>)
│ │ └── Table.Column (<th>, allowsSorting, etc.)
│ │ └── Table.ColumnResizer (optional)
│ └── Table.Body (<tbody>, items, renderEmptyState)
│ ├── Table.Row (<tr>)
│ │ └── Table.Cell (<td>)
│ └── Table.LoadMore (optional, infinite scroll)
│ └── Table.LoadMoreContent
└── Table.Footer (optional, pagination, etc.)
항목 식별(Item Identity)
v2: React의 key를 목록 재조정과 선택 상태에 모두 사용했어요.
v3: 선택/정렬 상태에는 Table.Row와 Table.Column에 id를 사용하고, 목록에는 React key를 유지해요.
요약
- Imports: 분리된 named imports → 점 표기법의 단일
Tableimport - 새 래퍼:
Table.ScrollContainer와Table.Content가 테이블 구조를 감쌈 - Props 이동:
aria-label,selectionMode,sortDescriptor등이Table에서Table.Content로 이동 - 하단 콘텐츠:
bottomContentprop →Table.Footer합성 컴포넌트 - 상단 콘텐츠:
topContentprop →Table.ScrollContainer앞의Table안에 콘텐츠 배치 - 선택 체크박스: 자동 렌더링 →
slot="selection"이 있는 명시적Checkbox - 빈 상태:
emptyContentprop →Table.Body의renderEmptyState - 로딩:
loadingState/loadingContent→ 무한 스크롤용Table.LoadMore - 열 크기 조정: 새
Table.ResizableContainer와Table.ColumnResizer - 항목 식별: 행과 열에
key→id - 스타일링 Props 제거:
color,radius,shadow,isStriped,isCompact→ Tailwind CSS 사용 - classNames 제거: 개별 합성 컴포넌트에
className사용