본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

스켈레톤(Skeleton) v2 → v3 마이그레이션

원문 보기 위키 갱신

HeroUI v2의 Skeleton을 v3으로 옮길 때 필요한 변경을 정리한 가이드예요. 가장 큰 변화는 Skeleton이 더 이상 자식 요소를 감싸지 않고, 표시 여부도 스스로 관리하지 않는다는 점이에요. 이제 독립적인 자리표시자(placeholder)가 되어 표시 여부를 직접 제어해야 해요. 동작과 props가 어떻게 달라지는지 차근차근 살펴볼게요.

출처: HeroUI

본문

참고: 완전한 API 레퍼런스, 스타일링 가이드, 고급 예제는 v3 Skeleton 문서를 참고하세요. 이 가이드는 HeroUI v2에서 마이그레이션하는 부분에만 집중합니다.

구조 변화

v2에서는 Skeleton이 자식 요소를 감싸고 isLoaded에 따라 표시/숨김을 처리했어요:

import { Skeleton } from "@heroui/react";

export default function App() {
  const isLoaded = false;
  
  return (
    <Skeleton isLoaded={isLoaded}>
      <div className="h-24 bg-secondary" />
    </Skeleton>
  );
}

v3에서는 Skeleton이 표시 여부를 직접 제어하는 독립적인 자리표시자예요:

import { Skeleton } from "@heroui/react";

export default function App() {
  const isLoaded = false;
  
  return (
    <>
      {!isLoaded ? (
        <Skeleton className="h-24 rounded-lg" />
      ) : (
        <div className="h-24 bg-secondary" />
      )}
    </>
  );
}

주요 변경 사항

1. 컴포넌트 동작

v2: 자식 요소를 감싸고 isLoaded에 따라 표시/숨김 처리 v3: 독립적인 자리표시자 - 직접 표시 여부를 제어

2. Prop 변경

v2 Prop v3 Location Notes
isLoaded — Control visibility manually with conditional rendering
disableAnimation animationType Use animationType="shimmer" | "pulse" | "none" (use "none" to disable)
classNames — Use className prop directly
children — Skeleton no longer wraps content

3. 새 Props

  • animationType - 애니메이션 타입을 제어: "shimmer"(기본값), "pulse", 또는 "none"

마이그레이션 예제

로드된 상태와 함께

v2:

import { useState } from "react";

const [isLoaded, setIsLoaded] = useState(false);

<Skeleton className="rounded-lg" isLoaded={isLoaded}>
  <div className="h-24 rounded-lg bg-secondary" />
</Skeleton>

v3:

import { useState } from "react";

const [isLoaded, setIsLoaded] = useState(false);

{!isLoaded ? (
  <Skeleton className="h-24 rounded-lg" />
) : (
  <div className="h-24 rounded-lg bg-secondary" />
)}

독립적인 Skeleton

v2:

<div className="flex items-center gap-3">
  <Skeleton className="flex rounded-full w-12 h-12" />
  <div className="w-full flex flex-col gap-2">
    <Skeleton className="h-3 w-3/5 rounded-lg" />
    <Skeleton className="h-3 w-4/5 rounded-lg" />
  </div>
</div>

v3:

<div className="flex items-center gap-3">
  <Skeleton className="h-12 w-12 shrink-0 rounded-lg" />
  <div className="flex-1 space-y-2">
    <Skeleton className="h-3 w-full rounded" />
    <Skeleton className="h-3 w-4/5 rounded" />
  </div>
</div>

애니메이션 타입

v2:

{/* Shimmer (default) */}
<Skeleton>
  <div className="h-24 bg-default-300" />
</Skeleton>

{/* No animation */}
<Skeleton disableAnimation>
  <div className="h-24 bg-default-300" />
</Skeleton>

v3:

{/* Shimmer (default) */}
<Skeleton animationType="shimmer" className="h-24 rounded-lg" />

{/* Pulse */}
<Skeleton animationType="pulse" className="h-24 rounded-lg" />

{/* No animation */}
<Skeleton animationType="none" className="h-24 rounded-lg" />

복잡한 예제: 콘텐츠가 있는 카드

v2:

import { useState } from "react";

const [isLoaded, setIsLoaded] = useState(false);

<Card className="w-[200px] space-y-5 p-4" radius="lg">
  <Skeleton className="rounded-lg" isLoaded={isLoaded}>
    <div className="h-24 rounded-lg bg-secondary" />
  </Skeleton>
  <div className="space-y-3">
    <Skeleton className="w-3/5 rounded-lg" isLoaded={isLoaded}>
      <div className="h-3 w-full rounded-lg bg-secondary" />
    </Skeleton>
    <Skeleton className="w-4/5 rounded-lg" isLoaded={isLoaded}>
      <div className="h-3 w-full rounded-lg bg-secondary-300" />
    </Skeleton>
  </div>
</Card>

v3:

import { useState } from "react";

const [isLoaded, setIsLoaded] = useState(false);

<Card className="w-[250px] space-y-5 rounded-lg p-4">
  {!isLoaded ? (
    <>
      <Skeleton className="h-32 rounded-lg" />
      <div className="space-y-3">
        <Skeleton className="h-3 w-3/5 rounded-lg" />
        <Skeleton className="h-3 w-4/5 rounded-lg" />
      </div>
    </>
  ) : (
    <>
      <div className="h-32 rounded-lg bg-secondary" />
      <div className="space-y-3">
        <div className="h-3 w-3/5 rounded-lg bg-secondary" />
        <div className="h-3 w-4/5 rounded-lg bg-secondary-300" />
      </div>
    </>
  )}
</Card>

동기화된 심머(Shimmer) 효과

v3에서는 모든 스켈레톤 요소를 한 번에 지나가는 동기화된 심머를 만들 수 있어요. 부모 컨테이너에 skeleton--shimmer 클래스를 적용하고 각 자식 Skeleton에 animationType="none"을 설정하세요:

{/* The parent container drives a single shimmer across all children */}
<div className="skeleton--shimmer space-y-4 rounded-lg p-4">
  <Skeleton animationType="none" className="h-32 rounded-lg" />
  <div className="space-y-3">
    <Skeleton animationType="none" className="h-3 w-3/5 rounded-lg" />
    <Skeleton animationType="none" className="h-3 w-4/5 rounded-lg" />
  </div>
</div>

이것은 각 스켈레톤이 독립적으로 애니메이션되는 대신 단일하고 통일된 심머 스윕을 원하는 카드 같은 레이아웃에 유용해요.

전역 애니메이션 설정

v3에서는 CSS 변수를 사용해 기본 애니메이션 타입을 전역으로 설정할 수 있어요:

:root {
  --skeleton-animation: pulse; /* shimmer, pulse, or none */
}

이 값은 개별 컴포넌트의 animationType prop으로 덮어쓸 수 있어요.

요약

  1. 자식 요소 감싸기 없음: Skeleton은 더 이상 자식 요소를 감싸지 않아요 — 독립적인 자리표시자
  2. isLoaded prop 없음: 조건부 렌더링으로 표시 여부를 직접 제어
  3. 애니메이션 제어: disableAnimation → animationType ("shimmer", "pulse", "none")
  4. 스타일링: classNames → className prop 직접 사용
  5. 단순화된 API: 자리표시자에 집중하는 훨씬 단순한 컴포넌트
  6. 동기화된 심머: 통일된 심머 스윕을 위해 자식에는 animationType="none", 부모 컨테이너에는 skeleton--shimmer 클래스 사용

더 알아보기 (Learn more)