Created
December 5, 2021 11:22
-
-
Save officialrajdeepsingh/d231cbdbcc130cf87c81d62f772f9e46 to your computer and use it in GitHub Desktop.
This example of loader in next.js https://codesandbox.io/s/nextjs-example-of-image-loader-bkcfs?file=/pages/index.js:0-818
This file contains hidden or 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 Image from "next/image"; | |
function GraphCMSImageLoader({ src, width }) { | |
const relativeSrc = (src) => src.split("/").pop(); | |
return `https://media.graphcms.com/resize=width:${width}/${relativeSrc(src)}`; | |
} | |
function IndexPage({ products }) { | |
return ( | |
<div className="gap-6 grid grid-cols-1 md:grid-cols-3"> | |
{products.map((product) => { | |
console.log(product.image.url, " product.image.url"); | |
return ( | |
<div key={product.id}> | |
<Image | |
loader={GraphCMSImageLoader} | |
src={product.image.url} | |
width={400} | |
height={400} | |
/> | |
<h2 className="font-semibold text-lg">{product.name}</h2> | |
</div> | |
); | |
})} | |
</div> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment