File tree Expand file tree Collapse file tree 2 files changed +12
-0
lines changed
packages/common/src/components Expand file tree Collapse file tree 2 files changed +12
-0
lines changed Original file line number Diff line number Diff line change 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+ } ;
Original file line number Diff line number Diff line change 11import { CenteredPage as CenteredPageComponent } from "./centered_page" ;
22import { CommonContextProvider as CommonContextProviderComponent } from "./common_context" ;
33import { ErrorFallback as ErrorFallbackComponent } from "./error_handler" ;
4+ import { FallbackImage as FallbackImageComponent } from "./fallback_image" ;
45import { LinkHandler as LinkHandlerComponent } from "./link_handler" ;
56import {
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 {
You can’t perform that action at this time.
0 commit comments