Skip to content

Instantly share code, notes, and snippets.

@officialrajdeepsingh
Created December 5, 2021 11:22
Show Gist options
  • Save officialrajdeepsingh/d231cbdbcc130cf87c81d62f772f9e46 to your computer and use it in GitHub Desktop.
Save officialrajdeepsingh/d231cbdbcc130cf87c81d62f772f9e46 to your computer and use it in GitHub Desktop.
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