MCPcopy Create free account
hub / github.com/dailydotdev/apps / ImageComponent

Function ImageComponent

packages/shared/src/components/image/Image.tsx:42–71  ·  view source on GitHub ↗
(
  { fallbackSrc, src, alt, fetchPriority = 'auto', ...props }: ImageProps,
  ref?: Ref<HTMLImageElement>,
)

Source from the content-addressed store, hash-verified

40};
41
42const ImageComponent = (
43 { fallbackSrc, src, alt, fetchPriority = 'auto', ...props }: ImageProps,
44 ref?: Ref<HTMLImageElement>,
45): ReactElement => {
46 const finalFallbackSrc =
47 fallbackSrc ?? fallbackSrcByType[props.type ?? ImageType.Post];
48
49 const onError = (event: SyntheticEvent<HTMLImageElement>): void => {
50 if (finalFallbackSrc && finalFallbackSrc !== event.currentTarget.src) {
51 // eslint-disable-next-line no-param-reassign
52 event.currentTarget.src = finalFallbackSrc;
53 if (event.currentTarget.srcset) {
54 // eslint-disable-next-line no-param-reassign
55 event.currentTarget.srcset = finalFallbackSrc;
56 }
57 }
58 };
59
60 return (
61 <img
62 {...props}
63 /* @ts-expect-error - Not supported by react yet */ /* eslint-disable react/no-unknown-property */
64 fetchpriority={fetchPriority}
65 ref={ref}
66 alt={alt}
67 src={src ?? finalFallbackSrc}
68 onError={onError}
69 />
70 );
71};
72
73export const Image = forwardRef(ImageComponent);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected