I am wanting to create a data file for my project instead of having everything in the one file, however I am using React hooks to load in images. This becomes a problem when I want to have everything in separate files. The code gives me the 'Invalid hook call' message which I understand why it is wrong, but can't figure out how to get it to work for me.
EventData.js
import React from "react"
import Image from "gatsby-image"
import { graphql, useStaticQuery } from "gatsby"
const getImages = graphql`
{
btu: file(relativePath: { eq: "eventImage/btu.jpeg" }) {
childImageSharp {
fixed(height: 120, width: 500) {
...GatsbyImageSharpFixed_withWebp_tracedSVG
}
}
}
}
`
const data = useStaticQuery(getImages)
export const details = [
{
id: 1,
img: <Image fixed={data.btu.childImageSharp.fixed} />,
date: "2 Oct 2020",
distance: "30km - 160km",
name: "Brisbane Trail Ultra",
location: "Brisbane, QLD",
},
]
EventCalendar.js
const EventCalendar = () => {
return (
<Layout>
<section>
{details.map(details => {
return <EventCard key={details.id} {...details}></EventCard>
})}
</section>
</Layout>
)
}