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

Image (이미지)

원문 보기 위키 갱신

이미지 요소와 로딩·에러 상태에 대한 선택적 폴백(fallback)을 제공하는 컴포넌트예요. 이미지가 로딩 중이거나 로드에 실패했을 때 대체 콘텐츠를 표시할 수 있고, 로딩 중 콘텐츠가 깜빡이는(flash) 현상을 방지하도록 지연도 설정할 수 있어요.

출처: 문서

본문

Import (불러오기)

import { Image } from "@kobalte/core/image";
// or
import { Root, Img, ... } from "@kobalte/core/image";
// or (deprecated)
import { Image } from "@kobalte/core";

Features (기능)

  • 이미지가 렌더링되는 시점을 자동 또는 수동으로 제어할 수 있어요.
  • 폴백 부분(Fallback)은 어떤 children이든 받을 수 있어요.
  • 콘텐츠가 깜빡이는 현상을 방지하도록 폴백 렌더링을 선택적으로 지연할 수 있어요.

Anatomy (구조)

이미지는 다음의 부분들로 이루어져요:

  • Image: 이미지의 루트 컨테이너예요.
  • Image.Img: 렌더링할 이미지예요. 기본적으로 이미지가 로드된 뒤에만 렌더링돼요.
  • Image.Fallback: 이미지가 아직 로드되지 않았을 때 렌더링되는 요소예요. 로딩 중이거나 에러가 발생한 상황을 의미해요.
<Image>
	<Image.Img />
	<Image.Fallback />
</Image>

Example (예제)

기본 예제를 통해 이미지의 구조와 스타일링 방식을 확인해 보세요. 인터랙티브한 미리보기는 출처 문서에서 직접 확인할 수 있어요.

Usage (사용법)

Avoid flash during loading (로딩 중 깜빡임 방지)

기본적으로 Image.Fallback은 이미지가 아직 로드되지 않았을 때 렌더링돼요. 즉 로딩 중이거나 에러가 발생한 상황을 말해요.

로딩 중 깜빡임이 발생한다면 fallbackDelay prop을 사용해 폴백 렌더링을 지연시킬 수 있어요. 이렇게 하면 인터넷 연결이 느린 사용자에게만 폴백이 표시돼요.

<Image fallbackDelay={600} class="image">
	<Image.Img
		class="image__img"
		src="https://randomuser.me/api/portraits/women/44.jpg"
		alt="Nicole Steeves"
	/>
	<Image.Fallback class="image__fallback">NS</Image.Fallback>
</Image>

API Reference (API 참조)

Image

Image은 @kobalte/core/image의 Root 임포트(그리고 더 이상 사용되지 않는 Image.Root)와 동일해요.

Prop Description
fallbackDelay number
The delay (in ms) before displaying the image fallback. Useful if you notice a flash during loading for delaying rendering, so it only appears for those with slower internet connections.
onLoadingStatusChange (status: "idle" | "loading" | "loaded" | "error") => void
A callback providing information about the loading status of the image. This is useful in case you want to control more precisely what to render as the image is loading.

Rendered elements (렌더링되는 요소)

Component Default rendered element
Image span
Image.Img img
Image.Fallback span

더 알아보기 (Learn more)