admin管理员组文章数量:1290964
Hello I'm using Nextjs for my portfolio and I'm using static pictures, the problem I find with the placeholder="blur" on next/image Image component is it doesn't work when I'm mapping through an array to display multiple pictures, the problem i get us this:
Error: Image with src "" has "placeholder='blur'" property but is missing the "blurDataURL" property. Possible solutions: - Add a "blurDataURL" property, the contents should be a small Data URL to represent the image - Change the "src" property to a static import with one of the supported file types: jpeg,png,webp,avif (animated images not supported) - Remove the "placeholder" property, effectively no blur effect Read more:
Now here it's demanding the blurDataURL while I'm only using static imported pictures which are mapped through in an Array.
import scrumCourse from "@/assets/images/scrumCert.webp"
the array:
const certificates = [{
name: "scrum-cert",
avatar: scrumCourse, // statically imported picture
link: "https://udemy..........", },]
Here is snippet of my code :
{[...new Array(10)].fill(0).map((_, index) => (
<Fragment key={index}>
{certificates.map(certificate => (
<Card key={certificate.name} className="max-w-[400px] md:max-w-md p-2 md:p-4 items-center transition duration-300 hover:rotate-1">
<Link href={certificate.link} target="_blank" >
<div className="relative w-[416px] h-[321.45px] object-cover">
<Image
src={certificate.avatar}
alt={certificate.name}
placeholder="blur"
fill
className="max-h-full rounded-3xl" />
</div>
</Link>
</Card>
))}
</Fragment>
))
Hello I'm using Nextjs for my portfolio and I'm using static pictures, the problem I find with the placeholder="blur" on next/image Image component is it doesn't work when I'm mapping through an array to display multiple pictures, the problem i get us this:
Error: Image with src "" has "placeholder='blur'" property but is missing the "blurDataURL" property. Possible solutions: - Add a "blurDataURL" property, the contents should be a small Data URL to represent the image - Change the "src" property to a static import with one of the supported file types: jpeg,png,webp,avif (animated images not supported) - Remove the "placeholder" property, effectively no blur effect Read more: https://nextjs./docs/messages/placeholder-blur-data-url
Now here it's demanding the blurDataURL while I'm only using static imported pictures which are mapped through in an Array.
import scrumCourse from "@/assets/images/scrumCert.webp"
the array:
const certificates = [{
name: "scrum-cert",
avatar: scrumCourse, // statically imported picture
link: "https://udemy..........", },]
Here is snippet of my code :
{[...new Array(10)].fill(0).map((_, index) => (
<Fragment key={index}>
{certificates.map(certificate => (
<Card key={certificate.name} className="max-w-[400px] md:max-w-md p-2 md:p-4 items-center transition duration-300 hover:rotate-1">
<Link href={certificate.link} target="_blank" >
<div className="relative w-[416px] h-[321.45px] object-cover">
<Image
src={certificate.avatar}
alt={certificate.name}
placeholder="blur"
fill
className="max-h-full rounded-3xl" />
</div>
</Link>
</Card>
))}
</Fragment>
))
Share
Improve this question
edited Feb 14 at 13:13
AmineDev
asked Feb 13 at 20:14
AmineDevAmineDev
234 bronze badges
1 Answer
Reset to default 0According to Nextjs official Docs
https://nextjs./docs/app/building-your-application/optimizing/images#local-images
https://nextjs./docs/app/api-reference/components/image#placeholder
if you specified option blur
for placeholder
prop, then you should specify blurDataURL
prop also (which, btw, is what the error is telling you to do)
Only an exception to this case is when you use static imports
By static imports, it means
import image from './images/image1.png'
and pass it this way
<Image
src={image}
placeholder='blur'
/>
In this case only, the static image will be used as blurData because it can be fetched in buildtime
other than that you should specify blurDataURL
I see you are providing the src dynamically through certificate.link
So you either import your images statically OR provide a blurDataURL
本文标签:
版权声明:本文标题:reactjs - Using nextimage while maping through an array with static pictures and using placeholder="blur" - St 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741507312a2382396.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论