#<Images> Size in item.images error

2 messages · Page 1 of 1 (latest)

primal hollow
#

Hello everyone. Please tell me, how to insert variables from Sanity into the image string?

import { client, urlFor } from '@/lib/utils'
import { Base } from '@/lib/types'

import Image from 'next/image'
import Link from 'next/link'

async function getData() {
  const query = `*[_type == "base"] | order(_createdAt asc) {
    _id,
    name,
    "slug": slug.current,
    cover {width, height, "image": asset->url},
    price,
    description,
    background
  }`

  const data = await client.fetch(query)

  return data
}

export const dynamic = 'force-dynamic'

export default async function Base() {
  const data: Base[] = await getData()

  return (
    <div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-6">
      {data.map((item) => (
        <Link
          key={item._id}
          href={`/subscribe/${item.slug}`}>
          <div
            className={`${item.background} p-4 block border rounded-lg h-full`}>
            <Image
              src={urlFor(item.cover.image).url()}
              alt={item.name}
              className={`w-[${item.cover.width}px] h-[${item.cover.height}px]`}
              width={item.cover.width}
              height={300}
            />
            {item.price}
            {item.description}
          </div>
        </Link>
      ))}
    </div>
  )
}

dreamy quartzBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)