GatsbyImage - src with props #31326
Unanswered
robertocerdasilva
asked this question in
Help
Replies: 1 comment 3 replies
-
import React from 'react'
import { StaticImage } from 'gatsby-plugin-image'
export default Avatar = ({ image }) => {
const imageProps = {
width: 36,
quality: 90,
formats: ['PNG'],
alt: '',
className="rounded-circle mr-2"
}
if (image === "image1") {
return <StaticImage src="../../images/image1.png" {...imageProps} />
} else if (image === "image2") {
return <StaticImage src="../../images/image2.png" {...imageProps} />
} else {
return <StaticImage src="../../images/image3.png" {...imageProps} />
}
} But if you can have a dynamic number of images, you cannot use |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
hello everyone, i have a problem displaying an image.
I already saw the documentation and understand that the "src" property cannot be used with variables.
But the documentation to show a dynamic image I cannot understand it because every time I try to apply its examples I do not get the desired result.
In my files I have the following images:
My component:
Import Component:
<Avatar image="image1"/>
how can I do this using GatsbyImage? any good and simple example?
Thank you!
Beta Was this translation helpful? Give feedback.
All reactions