I am new to Gatsby and its graphQL query system to retrieve assets. I have a working component Image
that fetches an image and displays it. I want to have the name of the image customizable but I can't figure out how to dit.
Here is the working component:
const Image = () => (
<StaticQuery
query={graphql`
query {
// fetching the image gatsby-astronaut.png
placeholderImage: file(relativePath: { eq: "gatsby-astronaut.png" }) {
childImageSharp {
fluid(maxWidth: 300) {
...GatsbyImageSharpFluid
}
}
}
}
`}
render={data => <Img fluid={data.placeholderImage.childImageSharp.fluid} />}
/>
);
And here is what I tried to have a customizable image:
const Image = ({ imgName }: { imgName: string }) => (
<StaticQuery
query={graphql`
query {
// fetching the image imgName
placeholderImage: file(relativePath: { eq: "${imgName}.png" }) {
childImageSharp {
fluid(maxWidth: 300) {
...GatsbyImageSharpFluid
}
}
}
}
`}
render={data => <Img fluid={data.placeholderImage.childImageSharp.fluid} />}
/>
);
But it raises the following error for the query:
Expected 1 arguments, but got 2.ts(2554)
How can I have a customizable image name?