Created
April 6, 2023 18:37
-
-
Save treckstar/1293859c06acb37398884120f693a8b7 to your computer and use it in GitHub Desktop.
Class based Image loader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
import { Image, ImageProps } from "next/image"; | |
type ImageLoaderProps = Omit<ImageProps, "src"> & { | |
src: string; | |
}; | |
class ImageLoader extends React.Component<ImageLoaderProps> { | |
public loader({ src, width, quality }: ImageLoaderProps): string { | |
return `${src}?w=${width}&q=${quality || 75}`; | |
} | |
public render(): JSX.Element { | |
const { src, ...props } = this.props; | |
return <Image loader={this.loader} src={src} {...props} />; | |
} | |
} | |
export default ImageLoader; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment