Skip to content

Commit 0b727b2

Browse files
committed
feat: FallbackImage 컴포넌트 추가
1 parent 989db1d commit 0b727b2

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import * as React from "react";
2+
3+
type FallbackImageProps = React.ComponentProps<"img"> & {
4+
errorFallback: React.ReactNode;
5+
};
6+
7+
export const FallbackImage: React.FC<FallbackImageProps> = ({ src, alt, errorFallback }) => {
8+
const [isError, setIsError] = React.useState(!src ? true : false);
9+
return isError ? errorFallback : <img src={src} alt={alt} onError={() => setIsError(true)} />;
10+
};

packages/common/src/components/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { CenteredPage as CenteredPageComponent } from "./centered_page";
22
import { CommonContextProvider as CommonContextProviderComponent } from "./common_context";
33
import { ErrorFallback as ErrorFallbackComponent } from "./error_handler";
4+
import { FallbackImage as FallbackImageComponent } from "./fallback_image";
45
import { LinkHandler as LinkHandlerComponent } from "./link_handler";
56
import {
67
LottieDebugPanel as LottieDebugPanelComponent,
@@ -35,6 +36,7 @@ namespace Components {
3536
export const LottiePlayer = LottiePlayerComponent;
3637
export const NetworkLottiePlayer = NetworkLottiePlayerComponent;
3738
export const ErrorFallback = ErrorFallbackComponent;
39+
export const FallbackImage = FallbackImageComponent;
3840
export const LinkHandler = LinkHandlerComponent;
3941

4042
export namespace MDX {

0 commit comments

Comments
 (0)