-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathImageBase.tsx
28 lines (23 loc) · 1.02 KB
/
ImageBase.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import React, {CSSProperties, MouseEventHandler, ReactEventHandler} from 'react';
import {ImageContext} from '../../context/imageContext/imageContext';
import {ImageObjectProps} from '../../models';
export interface ImageBaseProps extends Partial<ImageObjectProps> {
style?: CSSProperties;
className?: string;
onClick?: MouseEventHandler;
onLoad?: ReactEventHandler<HTMLDivElement>;
onError?: () => void;
}
export const ImageBase = ({fetchPriority, alt, ...props}: ImageBaseProps) => {
const {Image} = React.useContext(ImageContext);
return Image ? (
<Image fetchPriority={fetchPriority} alt={alt} {...props} />
) : (
// There is an issue with fetchpriority attr in img in React.
// It is still not supported. However it's nice to have ability to manage
// this prop is good to have to improve Core Web Vitals.
// So, here is a workaround to assign the attr.
<img {...{fetchpriority: fetchPriority}} alt={alt} {...props} />
);
};
export default ImageBase;