This is the code for a single image in any other Javascript framework in existence:
<img src="images/someFile.png" />
... possibly with some styling.
This is the code for a single image in Gatsby (basically copied from the Gatsby Image documentation page, https://www.gatsbyjs.org/docs/gatsby-image/ ... and this is just a simple example):
import { useStaticQuery, graphql } from "gatsby"
import Img from "gatsby-image"
export default function Image() {
const data = useStaticQuery(graphql`
query {
file(relativePath: { eq: "images/someFile.png" }) {
childImageSharp {
fixed {
...GatsbyImageSharpFixed
}
}
}
}
`)
return (
<Img fixed={data.file.childImageSharp.fixed} />
)
}
Holy hell, I'm supposed to write all that code (ok, I don't have to repeat the imports, but still) for every image in my site?!?
That can't be right, so clearly I'm not understanding something. Can someone please clarify what I'm not getting about Gatsby?
If it truly takes that much code to just to add one image to a site, Gatsby must be the slowest framework ever to develop in (but from it's popularity I can't believe that's true). Or do most Gatsby sites just use very few images?
See Importing Assets Directly Into Files and Using the Static Folder
import React from "react"
import importedImage from "../images/gatsby-icon.png"
const IndexPage = () => (
<>
<img src={importedImage} alt="Description of my imported image" />
<img
src="staticfolderimage.jpeg"
alt="Description of my image in the ./static folder"
/>
</>
)
export default IndexPage