import { ImageProps } from 'next/image'
import { Image } from '@builder.io/sdk-react'
import { useMemo } from 'react'
import { parseUrl, stringify } from 'query-string'
import { omitEmptyValues } from '@/utils/index'
export default function BuilderImage(props: ImageProps & Iprops) {
const { src, quality = 85, format = 'webp', imgWidth, imgHeight, fit, position, alt, ...rest } = props
const imgUrl = useMemo(() => {
if (typeof src === 'string' && src?.includes('cdn.builder.io')) {
const { url } = parseUrl(src)
const params = { quality, height: imgHeight, width: imgWidth, format, fit, position }
const queryString = stringify(omitEmptyValues(params))
return `${url}${queryString ? `?${queryString}` : ''}`
}
return src
}, [src, quality, imgHeight, imgWidth, format, fit, position])
return <Image {...rest} className="w-100" altText={alt || 'builder-image'} image={imgUrl} />
}
If I use the image component from Builder, will it cause an increase in Visual Views? If I use the image component from Next.js, will it not cause this issue?