-
-
Notifications
You must be signed in to change notification settings - Fork 340
Expand file tree
/
Copy pathNetlifyImage.tsx
More file actions
44 lines (41 loc) · 853 Bytes
/
NetlifyImage.tsx
File metadata and controls
44 lines (41 loc) · 853 Bytes
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import * as React from 'react'
import { getNetlifyImageUrl } from '~/utils/netlifyImage'
type NetlifyImageProps = Omit<
React.ImgHTMLAttributes<HTMLImageElement>,
'src'
> & {
src: string
width?: number
height?: number
quality?: number
}
/**
* Optimized image component using Netlify Image CDN.
* @see https://docs.netlify.com/build/image-cdn/overview/
*/
export function NetlifyImage({
src,
width,
height,
quality,
alt = '',
loading = 'lazy',
decoding = 'async',
...props
}: NetlifyImageProps) {
const optimizedSrc = React.useMemo(
() => getNetlifyImageUrl(src, { width, height, quality }),
[src, width, height, quality],
)
return (
<img
src={optimizedSrc}
width={width}
height={height}
alt={alt}
loading={loading}
decoding={decoding}
{...props}
/>
)
}