I'm learning GraphQL and I tried to make a background photo at the Hero section. It does not work and I tried a lot to fix it. The code I used is below. Some modules are imported for other parts of the file. There is no error while running the code. The background photo just does not display. I also attached code from gatsby-config.js.
import React from 'react'
import styled from "styled-components"
import { StaticQuery, graphql } from 'gatsby'
import { StaticImage, GatsbyImage } from 'gatsby-plugin-image'
import { Form } from 'react-bootstrap'
import "bootstrap/dist/css/bootstrap.min.css"
const Hero = ({myBackground}) => {
return (
<HeroContainer>
<HeroBg>
{myBackground.allFile.edges.map(({node}) => (
<p key={node.id}>
{node.base}
</p>
))}
</HeroBg>
</HeroContainer>
export default Hero;
export const myBackground = graphql`
query MyQuery {
allFile {
edges {
node {
id
base
relativePath
relativeDirectory
childImageSharp {
gatsbyImageData
}
}
}
}
}
`
const HeroContainer = styled.div`
display: flex;
justify-content: center;
align-items: center;
padding: 0 1rem;
position: relative;
height: 100vh;
margin: -104px -8px -10px -8px;
color: #fff;
background-color: lightgreen;
`
const HeroBg = styled.div`
position: absolute;
height: 100vh;
top: 0;
bottom: 0;
right: 0;
left: 0;
width: 100%;
height: 100%;
overflow: hidden;
`
The gatsby-config.js file below:
plugins: [
`gatsby-plugin-react-helmet`,
`gatsby-plugin-image`,
`gatsby-plugin-styled-components`,
{
resolve: `gatsby-source-filesystem`,
options: {
name: `images`,
path: `${__dirname}/src/images`,
},
},
`gatsby-transformer-sharp`,
`gatsby-plugin-sharp`,
`gatsby-transformer-json`,
{
resolve: `gatsby-source-filesystem`,
options: {
path: `./src/data/`,
},
},